0

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 = "[email protected]";
$subject = "Hey";
$message = "Hello";
$headers = "From: [email protected]";

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

I do recieve the success message in my JS.

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

1 Answer 1

0

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 <[email protected]>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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