I have a contact form that gets from ajax parameters and uses them to send emails. The function is located in functions.php of my child theme for twentyfifteen:
// Contact form Ajax
add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form');
function submit_contact_form(){
if(isset($_POST['email'])) {
$email = $_POST['email'];
$email_to = "wawd@company.pro";
$email_subject = "You have a new email from $email via yyy.com website";
$message = $_POST['text'];
if( wp_mail( $email_to, $email_subject, $message ) ) {
// the message was sent...
echo 'The test message was sent. Check your email inbox.';
} else {
// the message was not sent...
echo 'The message was not sent!';
};
// wp_mail( $email_to, $email_subject, $message );
header("Content-Type: application/json", true);
echo json_encode( array("AJAX" => "Success") );
die();
}
}
error_reporting(E_ALL);
ini_set("display_errors", 1);
I'm getting a response of the message was not sent! AJAX: "Success"
.
Why my function isn't working?
Do I have to include something in my php file?
I var_dumped the parameters that I get from ajax, the are all displayed fine in the response with a status code of Status Code:200 OK
.