PHP邮件无法正常工作并返回false

时间:2016-08-24 10:49:16

标签: php email ubuntu

当我运行邮件功能时,

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

1 个答案:

答案 0 :(得分:0)

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

    <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>