admin管理员组文章数量:1122846
We have an AJAX handler called by jQuery.ajax() that takes a document stored on the server and mails it to the user. At the bottom there is a call to wp_mail like so:
$status_wpmail = wp_mail($recipient, $subject, $body, $headers, $filename);
Problem is the email never gets sent out, and any code after the wp_mail call never gets parsed, including a debug statement to dump out the value of $status_wpmail. The jqXHR response sent back to the page reports 'success' however.
I put in debug statements inside the handler to dump comments to a text file, and have confirmed statements are dumped to file right up to the wp_mail call. I've also enabled debugging statements per this link but I don't get any debug logs generated in wp-content.
Using a separate script to test wp_mail with a simple message and attachment I confirmed that wp_mail does work. I've also ruled out mail() as the culprit by installing the WP Mail SMTP plugin where this behaviour continues to persist.
Any ideas?
EDIT: I've opted for a workaround by directly calling phpmailer and skipping wp_mail. The message successfully sent after doing that. Still would be nice if anyone knows why wp_mail would hang like that.
We have an AJAX handler called by jQuery.ajax() that takes a document stored on the server and mails it to the user. At the bottom there is a call to wp_mail like so:
$status_wpmail = wp_mail($recipient, $subject, $body, $headers, $filename);
Problem is the email never gets sent out, and any code after the wp_mail call never gets parsed, including a debug statement to dump out the value of $status_wpmail. The jqXHR response sent back to the page reports 'success' however.
I put in debug statements inside the handler to dump comments to a text file, and have confirmed statements are dumped to file right up to the wp_mail call. I've also enabled debugging statements per this link but I don't get any debug logs generated in wp-content.
Using a separate script to test wp_mail with a simple message and attachment I confirmed that wp_mail does work. I've also ruled out mail() as the culprit by installing the WP Mail SMTP plugin where this behaviour continues to persist.
Any ideas?
EDIT: I've opted for a workaround by directly calling phpmailer and skipping wp_mail. The message successfully sent after doing that. Still would be nice if anyone knows why wp_mail would hang like that.
Share Improve this question edited Oct 2, 2014 at 0:02 Denis Wong asked Oct 1, 2014 at 22:46 Denis WongDenis Wong 112 bronze badges 4- have you tried it without an attachment? – Milo Commented Oct 1, 2014 at 22:54
- Yup I've tried it without an attachment and also hardcoding in values. – Denis Wong Commented Oct 2, 2014 at 0:01
- What exactly are you calling through your AJAX-Request? An PHP File or an WP Action? – lippoliv Commented Oct 2, 2014 at 7:19
- Is your SMTP credentials set? Could you try setting them using these plugins and then use wp_mail(), WP SMTP - wordpress.org/plugins/wp-smtp WP Mail SMTP - wordpress.org/plugins/wp-mail-smtp – Domain Commented Oct 4, 2014 at 6:48
1 Answer
Reset to default 0You can do some simple debugging:
- Try:
wp_mail('youremail@com', '123', '123'); // to see if it will go through
- If #1 is not, check if you setup SMTP correctly
// install a smpt plugin(wp smtp mail/easy wp smtp)
and send a test email - If you can't send out a test email by plugin, check if your email account has correct rights to send out email from third party (like yahoo mail requires "generate an app password", etc https://wpmailsmtp.com/docs/how-to-set-up-the-other-smtp-mailer-in-wp-mail-smtp/#secure-yahoo)
- If you use correct method to configure your email settings, but email still doesn't go out, check if your web server blocks the port 25, 465 and 587 (telnet the email server with these ports)
My issue is wp_mail
is blocking "Reply-To" option in $headers
now, everything works fine from my AJAX request as long as "Reply-To" option is removed from $headers
. Not sure if you have same issue.
本文标签: wp mailwpmail() inside AJAX handler never returns
版权声明:本文标题:wp mail - wp_mail() inside AJAX handler never returns 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284851a1927337.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论