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' . "
" .
'Reply-To: info@mydomain.com' . "
" .
'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.
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 mydomain";
Here is one basic example to send html in email -
$to = 'abcd@gmail.com';
$from = "sender@gmail.com"; // sender
$subject = "Test email";
$message = '<html><body>';
$message .= "<p>This is The Email Address</p><br><span class='nonLink'>responder@example.com</span>";
$message .= '<br/><a href="http://www.yourwebsite.com/verify.php?email='.$from.'&hash='.$hash.'">click here to complete your registration</a>';
$message .= '</body></html>';
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset: utf8
";
// Additional headers
$headers .= "From: <$from>" . "
";
// Mail it
if (mail($to, $subject, $message, $headers)){
echo "email sent successfully";
}
There should NOT be anything before AND/or after EmailBody;
; it being the closing identifier.
Use this:
//ALL HTML MUST BE LEFT ALLIGNED.
$php_var="variable value";
$body = <<<EmailBody
<html>
<body>
$php_var
</body>
</html>
EmailBody;
$headers = 'From: info@mydomain.com' . "
" .
'Reply-To: info@mydomain.com' . "
" .
'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
Having something (space, text, etc.) after the closing identifier, will result in the following error:
Parse error: syntax error, unexpected end of file in....(path to file) on line X
had error reporting been set
Add this just before your opening <?php
tag:
error_reporting(E_ALL);
ini_set('display_errors', 1);