/* ========================================================================== Acesoftech Academy Contact Form Handler & Redirect Hook ========================================================================== */ function acesoftech_handle_contact_form_submission() { if ( isset( $_POST['contact_form_submit'] ) && ! empty( $_POST['contact_form_submit'] ) ) { $name = isset( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : ''; $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; $phone = isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : ''; $course = isset( $_POST['course'] ) ? sanitize_text_field( wp_unslash( $_POST['course'] ) ) : ''; $message = isset( $_POST['message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['message'] ) ) : ''; if ( ! empty( $name ) && ! empty( $phone ) ) { $admin_email = get_option( 'admin_email' ); $to = array( $admin_email, 'info@acesoftech.com', 'acesoftechacademy@gmail.com' ); $subject = "🔥 New Lead: " . $name . " interested in " . ( $course ? $course : 'IT Courses' ); $email_body = "

Acesoftech Academy - New Inquiry

A new student has submitted the contact inquiry form.

Student Name: " . esc_html( $name ) . "
Phone / WhatsApp: " . esc_html( $phone ) . "
Email Address: " . esc_html( $email ) . "
Selected Course: " . esc_html( $course ) . "
Message / Query: " . nl2br( esc_html( $message ) ) . "
Submission Time: " . current_time( 'F j, Y, g:i a' ) . "
"; $headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: Acesoftech Academy ', 'Reply-To: ' . $name . ' <' . $email . '>', ); @wp_mail( $to, $subject, $email_body, $headers ); // Redirect before any template output wp_redirect( home_url( '/thank-you/' ) ); exit; } } } add_action( 'template_redirect', 'acesoftech_handle_contact_form_submission' ); add_action( 'admin_post_nopriv_acesoftech_contact', 'acesoftech_handle_contact_form_submission' ); add_action( 'admin_post_acesoftech_contact', 'acesoftech_handle_contact_form_submission' );