【问题标题】:php email script not sending emailphp电子邮件脚本不发送电子邮件
【发布时间】: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>&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 错误,说该动词不被允许。这个问题已经解决了。

【问题讨论】:

  • 如果代码在其他网络托管服务上运行良好,建议您查看是否设置了 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 服务器被停止可能是您的问题。

标签: php email


【解决方案1】:

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

看看这个:

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

:-)

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        正如 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/

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

        【讨论】:

          猜你喜欢
          • 2011-09-16
          • 1970-01-01
          • 1970-01-01
          • 2012-09-12
          • 2011-04-28
          • 1970-01-01
          • 2014-08-17
          • 2012-08-25
          • 2015-01-20
          相关资源
          最近更新 更多