Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
484 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: [email protected] -- Headers: From: [email protected]  <[email protected]>  Reply-To: [email protected] <[email protected]>  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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...