There are three issues I see in your code:
-
Your form doesn’t have an
actionset. You should add it and set the value toadmin-post.php.<form method="POST" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">Because the function which processes the form and then sends the email is hooked to
admin_post_submit_support_ticket(i.e.admin_post_<action>) and that hook is fired only onwp-admin/admin-post.php. -
In
_submit_support_ticket(), theisset($_POST['support_ticket_hash'])should be! isset($_POST['support_ticket_hash'])because if not, the page would exit even if there was actually a valid nonce.if( ! isset($_POST['support_ticket_hash']) || ! wp_verify_nonce( $_POST['support_ticket_hash'], 'submit_support_ticket' ) ){ //echo ''; exit; } -
The email subject is actually empty and that will not send the email. So make sure that your “Request type” drop-down has valid options (currently, the
option‘svalueis empty).wp_mail( '[email protected]', '', 'Testing' ); // bad; subject is empty wp_mail( '[email protected]', 'Hi', 'Testing' ); // good; subject is good..In fact, if you look at
wp_mail()‘s docs, the subject is a required parameter. So once again, make sure the<option>has a good subject, although it might be preferred to compose the subject in your PHP and not sent as-is as coming from the form.<p><?php _e('Request type'); ?></p> <select name="support_ticket_type"> <option value="Support request"><?php _e('Support request'); ?></option> <option value="Modification request"><?php _e('Modification request'); ?></option> </select>
And after the email is sent, you should send the user back to the dashboard page to prevent them from seeing a blank page. So after the wp_mail() call, you could do:
wp_redirect( admin_url() );
exit;
Also, you should always sanitize user-supplied data. Never trust their input even if you actually trust the person…