php电子邮件脚本不发送电子邮件

时间:2010-09-16 12:45:10

标签: php email

我有一个脚本,用于从网站上的表单发送电子邮件。我知道代码很好 - 我之前已经测试过两个不同的托管公司。这次我在一个实际的服务器上使用它,而不是托管公司。基本上用户填写表单,点击提交并获取消息已发送的确认页面。唯一没有电子邮件来。这是脚本:

 $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>&nbsp; $email<br></br><br></br>
    <strong>Phone:</strong>&nbsp; $tel<br></br><br></br>
    <strong>Company:</strong>&nbsp; $comp<br></br><br></br>
    <a //href=\"javascript:history.go(-1)\"> Click here to return to the contact page.</a></br>";
}; 

?>

我不知道这是否重要,但直到最近,PHP才会在服务器上运行,并且出现HTTP错误405错误,表示不允许使用动词。这已经解决了。

4 个答案:

答案 0 :(得分:4)

祝贺。您已经创建了一个开放的垃圾邮件服务,允许每个人发送群发邮件。

检查出来:

http://www.securephpwiki.com/index.php/Email_Injection#php_mail.28.29_function

: - )

答案 1 :(得分:3)

PHP脚本甚至不想发送电子邮件,像sendmail,qmail或postfix这样的邮件服务器。检查它们是否配置良好。

答案 2 :(得分:3)

您的服务器很可能没有安装MTA(邮件传输代理)。 PHP的mail()函数本身不发送电子邮件,它将结果传递给系统的默认MTA。

快速提问 - 您使用的是基于Windows的服务器吗? Unix / Linux服务器的默认设置几乎总是有一个MTA(通常是sendmail或exim或者其他),但是Windows服务器通常不会;你必须自己安装一个。

答案 3 :(得分:2)

正如Elzo所说,邮件功能取决于在服务器上正确设置和配置邮件服务器。看看http://www.php.net/manual/en/book.mail.php 有关在php中设置邮件服务器访问的配置选项。

mail()本身只是底层功能的包装器。

如果您没有管理员权限,则运行时配置变量非常有用:

<?php 
ini_set("SMTP","smtp.example.com" ); 
ini_set('sendmail_from', 'user@example.com'); 
?> 

需要在系统配置文件中设置sendmail_path变量,如下所示:

sendmail_path = /usr/sbin/sendmail -t -i

如果您想要更好的错误报告并支持带有信息性消息的异常,当出现问题时,您应该查看phpmailer http://phpmailer.worxware.com/

它为您提供了一个相当不错的面向对象的界面,用于发送具有良好且信息量大的错误报告的电子邮件。