/** * 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 = 'thekavyasharma16@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; } admin | My Blog - Part 3

My Blog

My WordPress Blog