【问题标题】:PHP mail not working and returns falsePHP 邮件不工作并返回 false
【发布时间】:2016-08-24 10:49:15
【问题描述】:

当我运行邮件功能时,php 邮件返回 false

这是我的代码

$to = 'xxxxxx@gmail.com';
$subject = 'Login';
$message = 'Thanks for Login ! Your account has been logged on website.';
$headers = 'From:xxxxx@gmail.com' . "\r\n";
var_dump(mail($to, $subject, $message, $headers));

当我打开邮件日志时没有发现错误,当我测试使用此命令通过 ubuntu 终端发送邮件时

echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com

它正确地向我发送邮件

我也配置了 php.ini

sendmail_path = /usr/sbin/sendmail -t -i -f care@mydomain.com

【问题讨论】:

  • 您正在尝试从本地主机或实时服务器发送邮件??
  • 实时服务器在本地工作并返回 true
  • 检查你的标题
  • 当我在本地运行它返回 true 时,标题没有问题

标签: php email ubuntu


【解决方案1】:

首先尝试这个:使用此代码进行连接

    <html>

   <head>
      <title>Sending HTML email using PHP</title>
   </head>

   <body>

      <?php
         $to = "xyz@somedomain.com";
         $subject = "This is subject";

         $message = "<b>This is HTML message.</b>";
         $message .= "<h1>This is headline.</h1>";

         $header = "From:abc@somedomain.com \r\n";
         $header .= "Cc:afgh@somedomain.com \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";

         $retval = mail ($to,$subject,$message,$header);

         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }
      ?>

   </body>
</html>

【讨论】:

【解决方案2】:

我遇到了这个问题,但在我的情况下,这是由于我的后缀配置非常严格。我在 /var/log/maillog 中发现了这个错误:

postfix/sendmail[pid]: fatal: User apache(id) is not allowed to submit mail

解决方法是在 main.cf 中添加“apache”:

authorized_submit_users = root spamd apache

然后,别忘了重启 postfix

systemctl restart postfix

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    相关资源
    最近更新 更多