PHP

SEND EMAIL WITH HTML TEMPLATE IN PHP

THE HTML TEMPLATE <html><body>   <p>Hi {NAME}!</p> </body></html>

STRING REPLACE (A)

01

STRING REPLACE (B)

02

READ HTML INTO STRING & REPLACE $html = file_get_contents("template.html"); $html = str_replace("{NAME}", "Joe", $html);

PHP SEND MAIL mail("jon@doe.com", "subject", $html, implode("\r\n", [   "MIME-Version: 1.0",   "Content-type: text/html; charset=utf-8" ]));

THE HTML TEMPLATE <html><body>   <p>Hi <?=$name?>!</p> </body></html>

PHP VARIABLES (A)

03

PHP “LOAD TEMPLATE”  $name = "Joy";  ob_start(); include "template.php"; $html = ob_get_contents(); ob_end_clean();

PHP VARIABLES (B)

04

PHP SEND MAIL mail("joy@doe.com", "subject", $html, implode("\r\n", [   "MIME-Version: 1.0",   "Content-type: text/html; charset=utf-8" ]));