admin_url( 'admin-ajax.php' ) ) ); } add_action('wp_enqueue_scripts', 'contactform_add_script'); function ridolfi_contact_form_send() { $name=sanitize_text_field($_POST['name']); $email=sanitize_text_field($_POST['email']); $subject=sanitize_text_field($_POST['subject']); $phone=sanitize_text_field($_POST['phone']); $msg=sanitize_text_field($_POST['msg']); if(get_theme_mod('mail_to')) { $to = esc_html(get_theme_mod('mail_to')); }else { $to = get_option('admin_email'); } $body="
Name :".$name."
Email :".$email."
Subject :".$subject."
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', 'ridolfi_contact_form_send'); add_action('wp_ajax_nopriv_contact_form_send', 'ridolfi_contact_form_send'); ?>