【发布时间】:2010-09-16 12:45:10
【问题描述】:
我有一个用于从网站上的表单发送电子邮件的脚本。我知道代码很好 - 我之前曾与两家不同的托管公司进行过测试。这次我在实际服务器上使用它,而不是托管公司。基本上,用户填写表单,单击提交并获得消息已发送的确认页面。唯一的问题是没有电子邮件来。这是脚本:
$nickname = $_REQUEST['nickname'] ;
$email = $_REQUEST['email'] ;
$tel = $_REQUEST['tel'] ;
$comp = $_REQUEST['comp'] ;
$message = $_REQUEST['message'] ;
// Let's check if all fields are filled in!
if(empty($nickname) || empty($email) || empty($comp))
{
$error = "All of the required fields have not been completed, <a href=\"javascript:history.go(-1)\">please click here to go back.</a>";
}
else
{
$content= "$nickname has sent you an e-mail from XXX
Query:
$message
You can contact $nickname via Email: $email. <br />Other relevant details of individual: <br />Telephone Number: $tel <br />Company: $comp";
mail( "user@gmail.com", "Query", $content, "From: $email"); //first thing has to be address it is going to, then what the subject of the mail should be, the content and a from address which will be the query submitter.
echo "<h2>$nickname</h2><br></br>
Your query has been succesfully sent. <br></br><br></br>
We will deal with this query and be in touch as soon as possible.<br></br><br></br><br></br>
The contact details you submitted are: <br></br><br></br>
<strong>Email:</strong> $email<br></br><br></br>
<strong>Phone:</strong> $tel<br></br><br></br>
<strong>Company:</strong> $comp<br></br><br></br>
<a //href=\"javascript:history.go(-1)\"> Click here to return to the contact page.</a></br>";
};
?>
我也不知道这是否重要,但直到最近,PHP 无法在服务器上运行,并给出一个 HTTP 错误 405 错误,说该动词不被允许。这个问题已经解决了。
【问题讨论】:
-
如果代码在其他网络托管服务上运行良好,建议您查看是否设置了 smtp 或邮件发送服务。尝试做一个没有其他逻辑或代码的简单 mail() 作为健全性测试。
-
我有几个关于您的电子邮件问题的问题。您的服务器上是否安装了 Parellels Plesk?您是否在服务器上运行和设置了 SMTP 服务器?您的服务器是基于 Linux 还是基于 Windows?这是一个 Linux 设置:articles.sitepoint.com/article/advanced-email-php,这是一个 Windows 设置:geeklog.net/faqman/index.php?op=view&t=19
-
我对服务器不是很熟悉。我没有设置这个。我查了一下,在 IIS 管理器中看到 SMTP 虚拟服务器已停止,所以我想知道这是否是我的问题?
-
SMTP 服务器被停止可能是您的问题。