admin_url( 'admin-ajax.php' ) ) );
}
add_action('wp_enqueue_scripts', 'contactform_add_script');
function backyard_contact_form_send() {
$name=sanitize_text_field($_POST['name']);
$email=sanitize_text_field($_POST['email']);
$phone=sanitize_text_field($_POST['phone']);
$msg=sanitize_text_field($_POST['msg']);
$subject='Contact Detail';
$to = get_option('admin_email');
$body="
| Name : | ".$name." |
| Email : | ".$email." |
| Phone : | ".$phone." |
| Message : | ".$msg." |
";
$headers= "From: $name <$email>\n";
$headers.= "Reply-To: $subject <$email>\n";
$headers.= "Return-Path: $subject <$email>\n";
$headers.= "Content-type: text/html; charset=UTF-8 \r\n";
$headers.= "MIME-version: 1.0\n";
if (@mail($to, $subject, $body, $headers,"-f $email")){
print "Your message sent successfully." ;
} else {
print "Sorry! Please try again. "; }
die();
}
add_action('wp_ajax_contact_form_send', 'backyard_contact_form_send');
add_action('wp_ajax_nopriv_contact_form_send', 'backyard_contact_form_send');