How do i send mail with custom Form Data using WordPress

wp_mail is the function you are looking for.

You can take the posted form data ($_POST['email'], for example) and then use it to build and execute the wp_mail function. The example below was taken from https://developer.wordpress.org/reference/functions/wp_mail/#user-contributed-notes

$to = $_POST['email']; //[email protected]
$subject="The subject";
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );

Also the above script would need to check for malicious attacks or bad input from the user but the wp_mail function will allow you to send email.

Source:
https://developer.wordpress.org/reference/functions/wp_mail/

Leave a Comment