user1911703 user1911703 - 3 months ago 18
PHP Question

how to send html email using php

I would like to use <<< to send html email in php. So far i remember it works great previously but not working right now.

//ALL HTML MUST BE LEFT ALLIGNED.
$php_var="variable value";
$body = <<<EmailBody
<html>
<body>
$php_var
</body>
</html>
EmailBody; //EmailBody will not show in Email.
$headers = 'From: info@mydomain.com' . "\r\n" .
'Reply-To: info@mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject="Test HTML Email";
$body="test email from mydomain";
$to="aminulsumon@gmail.com";
mail($to,$subject,$body,$headers); //$header type should be html


any help is highly appreciated.

Answer

Remove the comment on the end of:

EmailBody; //EmailBody will not show in Email.

So it is only:

EmailBody;

Also you define $body twice, so take out:

$body="test email from vrexmedia-rail";