Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
489 views
in Technique[技术] by (71.8m points)

email - PHP @mail returning 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:UsersOwnerPhpstormProjectsCRMclassesCompanyNameEmail.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--
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...