PHP电子邮件脚本不发送电子邮件
我有一个脚本从网站上的表单发送电子邮件。我知道代码很好 - 我以前曾用两家不同的托管公司进行过测试。这次我在一个实际的服务器上使用它,而不是托管公司。基本上用户填写表单,点击提交并获取消息已发送的确认页面。唯一的不是电子邮件。下面是该脚本:PHP电子邮件脚本不发送电子邮件
$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("[email protected]", "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错误,说动词是不允许的。这已经解决了。
很有可能您的服务器没有安装MTA(邮件传输代理)。 PHP的mail()函数不会自己发送电子邮件,它会将结果传递给系统的默认MTA。
快速问题 - 您使用的是基于Windows的服务器吗? Unix/Linux服务器在其默认设置(通常是sendmail或exim或其他)中几乎总是有MTA,但Windows服务器通常不会;你必须自己安装一个。
PHP脚本甚至不会发送电子邮件,像sendmail,qmail或postfix这样的邮件服务器。检查它们是否配置良好。
作为Elzo已经表示,邮件功能依赖于邮件服务器在您的服务器上正确设置和配置。看看http://www.php.net/manual/en/book.mail.php 的配置选项,用于在php中设置邮件服务器访问。
mail()本身只是底层功能的包装。
如果您没有管理员权限运行时配置变量可以是非常有用的:
<?php
ini_set("SMTP","smtp.example.com");
ini_set('sendmail_from', '[email protected]');
?>
的sendmail_path变量需要的系统配置文件中设置这样的:
sendmail_path = /usr/sbin/sendmail -t -i
如果你想要更好的错误报告和支持异常信息的消息,当一些事情出错时,你应该看看phpmailer http://phpmailer.worxware.com/
它为您提供了一个相当不错的面向对象的接口,可以发送包含良好和翔实错误报告的电子邮件。
恭喜。您创建了一个开放的垃圾邮件服务,允许所有人发送群发邮件。
检查了这一点:
http://www.securephpwiki.com/index.php/Email_Injection#php_mail.28.29_function
:-)
如果代码适用于其他网站托管服务很好,我会建议你看看SMTP或邮寄发送服务设置。尝试做一个简单的邮件()没有其他逻辑或代码作为一个理智的测试。 – Extrakun 2010-09-16 12:49:01
我有几个有关您的电子邮件问题的问题。你的服务器上是否安装了Parellels Plesk?你有一台SMTP服务器在服务器上运行和设置吗?您的服务器是基于Linux还是Windows?这是一个Linux安装程序:http://articles.sitepoint.com/article/advanced-email-php这里是一个Windows安装程序:http://www.geeklog.net/faqman/index.php?op=view&t= 19 – 2010-09-16 12:51:42
我对服务器不太熟悉。我没有设置这个。我探讨了一下,并且我在IIS管理器中看到SMTP虚拟服务器已停止,所以我想知道这是否是我的问题? – 109221793 2010-09-16 12:57:19