Skip to content
For suggestions and any queries feel free to email me. Our team reply you with in few office hours. For More query email me at: guestpostenquiry@gmail.com
/**
* email sender function
*
*/
add_action('admin_post_nopriv_submit_contact_form', 'handle_contact_form_submission');
add_action('admin_post_submit_contact_form', 'handle_contact_form_submission');
function handle_contact_form_submission() {
$name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : '';
$email = isset($_POST['email']) ? sanitize_email($_POST['email']) : '';
$phone = isset($_POST['phone']) ? sanitize_text_field($_POST['phone']) : '';
$message = isset($_POST['message']) ? sanitize_textarea_field($_POST['message']) : '';
$to = 'guestpostenquiry@gmail.com'; // Your email
$subject = "New Contact Form Submission $name";
$body = "Name: $name\nEmail: $email\nPhone: $phone\n\nMessage:\n$message";
$headers = [
'Content-Type: text/plain; charset=UTF-8',
'From: '.$name.' <'.$email.'>',
'Reply-To: '.$email
];
$sent = wp_mail($to, $subject, $body, $headers);
wp_safe_redirect(home_url('/contact/?message=' . ($sent ? 'success' : 'error')));
exit;
}