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.

  • have you tried it without an attachment? – Milo Oct 1 '14 at 22:54
  • Yup I've tried it without an attachment and also hardcoding in values. – Denis Wong Oct 2 '14 at 0:01
  • What exactly are you calling through your AJAX-Request? An PHP File or an WP Action? – lippoliv Oct 2 '14 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 – WisdmLabs Oct 4 '14 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.