1// The Form:
2<form action="<?php echo esc_url( admin_url('admin-post.php') ); ?>" method="post">
3
4<input type="hidden" name="action" value="contact_form">
5
6// The Plugin or functions.php
7function prefix_send_email_to_admin() {
8 /**
9 * At this point, $_GET/$_POST variable are available
10 *
11 * We can do our normal processing here
12 */
13
14 // Sanitize the POST field
15 // Generate email content
16 // Send to appropriate email
17}
18add_action( 'admin_post_nopriv_contact_form', 'prefix_send_email_to_admin` );
19add_action( 'admin_post_contact_form', 'prefix_send_email_to_admin` );