I have a custom HTML form with input types and checkboxes. When I submit this form I want to send a mail will all the form details from the same php. How do I send the email from WordPress? I am pretty new and would thank for ur help.
3 Answers
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']; //sendto@example.com
$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/