I have set up a simple mailer before I get the full implementation sorted. I've tried a few email addresses but am not receiving them even though it returns 'true'. I'm using wp_ajax as well if that makes a difference.
functions.php
// Check for email return in share folders add_action( 'wp_ajax_share_email', 'share_email' ); add_action( 'wp_ajax_nopriv_share_email', 'share_email' ); function share_email(){ $email = $_POST['email']; // Return a boolean! $to = $email; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "[email protected]"; $headers = "From:" . $from; if(wp_mail($to,$subject,$message,$headers)) { return true; } else { return false; } }
Can anyone let me know why this isn't sending? Am I not allowed to use wp_mail and wp_ajax together perhaps?
Thanks
EDIT Jquery part
$('#share-pop .btn').click(function(){ var email = check.val(); jQuery.ajax({ type: 'POST', url: ajaxurl, data: {"action" : "share_email", 'email': email}, success: function(data){ if (data) { alert('sent'); } else { alert('An error occured'); } } }); });