当我使用wp_mail()
或mail()
函数在AJAX中,该函数不起作用,也不发送电子邮件。
当我只在函数中使用这些函数时。php文件它工作正常。
它与WordPress函数或操作无关。我已经检查了一切,包括使用SMTP邮件。SMTP邮件的工作原理与mail()
函数,它不会以AJAX模式发送。
这是我的职能。php文件内容:
add_action( \'phpmailer_init\', \'wpse8170_phpmailer_init\' );
function wpse8170_phpmailer_init( PHPMailer $phpmailer ) {
$phpmailer->Host = \'godadysmtpsampledomain.secureserver.net\';
$phpmailer->Port = 465; // could be different
$phpmailer->Username = \'sender@mysite.com\'; // if required
$phpmailer->Password = \'12345\'; // if required
$phpmailer->SMTPAuth = true; // if required
$phpmailer->SMTPSecure = \'ssl\'; // enable if required, \'tls\' is another possible value
$phpmailer->IsSMTP();
}
// This code works fine;
wp_mail("hossein@mydomain.net", "test", "test");
但是AJAX模式下的其他代码或插件,如Contact Form 7不起作用,这意味着电子邮件无法送达。我检查了这些插件wp_mail()
返回true,但电子邮件未送达。