javascript - 电子邮件功能在本地服务器上有效,但在 Web 服务器上无效
问题描述
我在一个网站上工作,几乎所有的工作。我已经测试了一个 javascript 函数来调用 php 电子邮件文件以在提交联系表单并按下发送时发送文件。这在我的本地 xampp 服务器上完美运行,但在用于生产的 plesk 服务器上却没有。Javascript函数是:
function emailproc()
{
xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", 'http://dougsguns.com/wp-content/themes/DougsGunsTheme/emailproc.php', true);
// xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
// var response = document.getElementById('send_response');
// response.display = "";
success();
}
else{
failure();
}
}
var formData = new FormData();
formData.append("txtName", document.getElementById('txtName').value);
formData.append("txtEmail", document.getElementById('txtEmail').value);
formData.append("txtCompany", document.getElementById('txtCompany').value);
formData.append("txtState", document.getElementById('txtState').value);
formData.append("txtAddress", document.getElementById('txtAddress').value);
formData.append("txtCity", document.getElementById('txtCity').value);
formData.append("txtState", document.getElementById('txtState').value);
formData.append("txtPostalCode", document.getElementById('txtPostalCode').value);
formData.append("txtPhone", document.getElementById('txtPhone').value);
formData.append("ddInterest", document.getElementById('ddInterest').value);
formData.append("txtHowFind", document.getElementById('txtHowFind').value);
formData.append("txtComments", document.getElementById('txtComment').value);
xmlHttp.send(formData);
alert("Sent");
return true;
}
function success()
{
window.location.href = "http://dougsguns.com/success/";
}
function failure()
{
window.location.href = "http://dougsguns.com/failure/";
}
这应该是获取表单字段,然后调用 emailproc.php 文件。它总是打开成功页面,但永远不会发送电子邮件。emailproc.php 文件是:
<?php
require_once("../../../wp-load.php");
print_r($_REQUEST);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_REQUEST['txtName'];
$email = $_REQUEST['txtEmail'];
$company = $_REQUEST['txtCompany'];
$state = $_REQUEST['txtState'];
$address = $_REQUEST['txtAddress'];
$city = $_REQUEST['txtCity'];
$state = $_REQUEST['txtState'];
$postal_code = $_REQUEST['txtPostalCode'];
$phone = $_REQUEST['txtPhone'];
$ddinterest = $_REQUEST['ddInterest'];
$howfind = $_REQUEST['txtHowFind'];
$comment = $_REQUEST['txtComments'];
}
$to = 'dgrd48@aol.com';
$subject = 'From Dougs Guns';
$body = "<body><h5>The following e-mail was sent from the Doug's Guns website :</h5>" .
"<hr />" .
"<p>Name: " . $name . "</p>" .
"<p>Email: " . $email . "<br />Company: " . $company . "<br />Address: " . $address . "<br />" .
"City: " . $city ."<br />State: " . $state . "<br />Postal Code: " . $postal_code . "<br />".
"Phone: " . $phone . "<br />".
"Interested In: " . $ddinterest . "<br /><br />".
"Discovered Website How: " . $howfind . "<br /><br />".
"Comment/question:<br />" . $comment . "<br /><br />"
;
//$headers = 'Content-Type: text/html; charset=UTF-8, From: Dougs Guns <dgrd48@aol.com';
mail( $to, $subject, $body, $headers);
?>
这是从 .asp 静态网站到 wordpress 网站的转换。任何帮助将不胜感激,如果您需要更多信息,请告诉我。谢谢你。
解决方案
推荐阅读
- swift - 滚动时隐藏 UITableView 复选标记
- amazon-web-services - AWS:子网中分配的 IP 列表
- javascript - 如何将不同表格和日期的数据显示到图表中
- docker - Docker 端口未正确公开
- spring-boot - Spring-boot 为辅助 SSL 侦听器配置 client-auth=need
- c++ - 不同类型特征矩阵之间算术后的模糊重载
- java - 将 Spring 与 Google Cloud SQL 连接时出错
- javascript - 如何在反应原生的js函数中使用apollo graphql(react)?
- ado.net - 提交事务请求没有对应的使用 ADO.net 的开始事务
- d3.js - D3.JS 树形图 - 点击顺序搞乱了数据