【发布时间】:2020-01-07 05:27:25
【问题描述】:
我正在尝试显示 PHPMailer SMTP 调试信息。 这没关系如果电子邮件失败但如果成功则发送两封电子邮件。
global $phpmailer;
$send = wp_mail( $to, 'Test Email', $message );
$phpmailer->SMTPDebug = 3;
ob_start();
$send = wp_mail( $to, 'Test Email', $message );
$smtp_debug = ob_get_clean();
echo "<pre>"; print_r( $smtp_debug ); echo "</pre>";
如果我删除第一个 wp_mail():
global $phpmailer;
$phpmailer->SMTPDebug = 3;
ob_start();
$send = wp_mail( $to, 'Test Email', $message );
$smtp_debug = ob_get_clean();
echo "<pre>"; print_r( $smtp_debug ); echo "</pre>";
它给出警告:
PHP 警告:从行中的空值创建默认对象:
$phpmailer->SMTPDebug = 3;
如果我删除第二个 wp_mail(),$smtp_debug 将为空。
那么,如何在成功时只发送一封电子邮件,在失败时也抓取错误?
【问题讨论】:
-
你初始化phpmailer类了吗?这是起点
$phpmailer= new PHPMailer(true);,然后是$phpmailer->SMTPDebug = 3;