dpvomqeu396484 2013-05-06 15:10
浏览 40

PHP @mail返回false

This code is not sending email, and I'm getting no errors to indicate why. How is one supposed to troubleshoot this?

    $uid = md5(uniqid(time()));
    $headers= "From: " . $this->fromAddress . "  <" . $this->fromName . ">
";
    $headers.= "Reply-To: " . $this->fromAddress . " <" . $this->fromName . ">
";
    if ($this->cc != "") { $headers .= "CC: ".$this->cc."
"; }
    if ($this->bcc != "") { $headers .= "BCC: ".$this->bcc."
"; }
    $headers .= "MIME-Version: 1.0
";
    $headers .= "Content-Type: multipart/mixed; boundary=\"" . $uid . "\"

";
    $headers .= "This is a multi-part message in MIME format.
";
    $headers .= "--" . $uid . "
";
    $headers .= "Content-type:text/html; charset=iso-8859-1
";
    $headers .= "Content-Transfer-Encoding: 7bit

";
    $headers .= $this->body . "

";
    $headers .= "--".$uid."--";

    $mail_sent = @mail($this->toAddress,$this->subject,'',$headers);

    if (!$mail_sent) {
        throw new Exception('Email failed to send');
    }

The result here is the Exception is thrown and nothing else. So @mail is returning false. Not much to go on ...

As an aside, the mail server is localhost (that does not require authentication) which sends email fine using similar code.

I have compared this code to the successful code and, although I'm obviously not seeing the critical piece, all of the differences seem to me to be unrelated to core email sending code.

The php mail log reads:

mail() on [C:\Users\Owner\PhpstormProjects\CRM\classes\CompanyName\Email.php:75]: To: lowens@companyname.com -- Headers: From: lowens@companyname.com  <lowens@companyname.com>  Reply-To: lowens@companyname.com <lowens@companyname.com>  MIME-Version: 1.0  Content-Type: multipart/mixed; boundary="7feeadcdbd29ed703423feb85438c14b"    This is a multi-part message in MIME format.  --7feeadcdbd29ed703423feb85438c14b  Content-type:text/html; charset=iso-8859-1  Content-Transfer-Encoding: 7bit    asdfasdf    --7feeadcdbd29ed703423feb85438c14b--
  • 写回答

2条回答 默认 最新

  • dongtanzhu5417 2013-05-06 15:12
    关注

    From the manual:

    the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

    Remove @ and any error messages won't be ignored.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题