PHPMailer,返回SMTP代码
我正在使用PHPMailer;
I'm using PHPMailer;
$oPM->SMTPDebug = 2;
$oPM->Debugoutput = 'html';
if ( !$oPM->send() ) echo "Mailer Error: " . $oPM->ErrorInfo;
else echo "Message sent!";
一次 $ oPM-> Send()
已经运行,我想收回SMTP状态代码,无论成功/失败。
Once $oPM->Send()
has ran, I would like to recive a SMTP Status Code, regardless of success/failure.
使用 SMTPDebug
选项,我可以得到它返回一个如下所示的字符串;
Playing with the SMTPDebug
option, I can get it to return a string as followed;
MAIL FROM命令失败:500 5.0.0信封从地址。我可以从字符串中获取代码。
但是真的希望有实际的代码返回。
I could grab the code from the string. But would really like to have the actual code returned.
这是可能的,还是应该走下去?谢谢!
Is this possible, or should I go down the strpos route? Thanks!
您不会直接从 send()
因为PHPMailer不一定使用SMTP。 SMTPDebug
输出不用于生产使用;可读取的错误消息将在 $ mail-> ErrorInfo
中显示。调用发送
后,可以从SMTP实例获取更准确的信息:
You won't get an SMTP code back directly from send()
because PHPMailer is not necessarily using SMTP. SMTPDebug
output isn't for production use; the readable error message will turn up in $mail->ErrorInfo
. You can get more precise info from the SMTP instance after calling send
:
$mail->getSMTPInstance()->getError();
它返回一个这样的结构:
which returns a structure like this:
[
'error' => '',
'detail' => '',
'smtp_code' => '',
'smtp_code_ex' => ''
]
顺便说一下,你的例子中嵌入的5.0.0错误是完全没用的为了诊断目的 - 这意味着它没有工作。不幸的是,您会发现,许多邮件服务器只是在正确报告错误时才是垃圾邮件,尤其是Exchange,所以如果你想要更准确的话,你将最终解析字符串。
Incidentally, the 5.0.0 error embedded in your example is completely useless for diagnostic purposes - all it means is "it didn't work". Unfortunately you'll find that many mail servers are just rubbish at reporting errors correctly, especially Exchange, so if you want to be more accurate, you will end up parsing strings.