Send emails using PHPMailler and wordpress REST API endpoint.
- Create a custom endpoint with POST request.
- Download PHPMailer (https://github.com/PHPMailer/PHPMailer) and upload it to your theme folder. Mine twenty nineteen.
- Create a folder inside your theme and add demo.html email template to it. The folder name should be "emails".
Remove
$mail->Body = $body;
and Add
$message = $body;
$message = str_replace('%myName%', 'My Name Is Bla Bla', $message);
$mail->msgHTML($message);
You can use 'myName' variable inside your email template like this
Hi, %myName%