New to WP and PHP:

I'm trying to send an email with AJAX. My wp_mail is returning true and I'm receiving no errors on GoDaddy where I'm hosting, but the email is never actually received. Here's my php function :

add_action("wp_ajax_send_email", "send_email");
add_action("wp_ajax_nopriv_send_email", "send_email");

function send_email() {
$to = "my_email@gmail.com";
$subject = "Hey";
$message = "Hello";
$headers = "From: wordpress@cmcenters.tv";

if (wp_mail($to, $subject, $message, $headers)) {
      echo json_encode(array('status' => 'success', 'message' => 'Contact message sent.'));
    } else {
      echo json_encode(error_get_last());

I do recieve the success message in my JS.

  • Sounds like a hosting/spam issue. Try 'message' => print_r( $GLOBALS['phpmailer'], true ) to see a more detailed report. – TheDeadMedic Nov 11 '16 at 17:20

Have you tried without the ajax? Is that where you're actually sending the mail? Try just putting the wp_mail function right under headers and see if you get the mail.

Also i agree with theDeadmedic. It could be spam. Check the google spam folder and if its' not there, try sending to an email on your own domain (as long as it's not using googles servers) Also, I always add content-type to my header to help reduce the spam flag. It may help you:

$headers = array('Content-Type: text/html; charset=UTF-8');
$headers[] = 'From: CMCENTERS <wordpress@cmcenters.tv>';

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.