Site icon Hip-Hop Website Design and Development

wp_mail() inside AJAX handler never returns

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.