Reputation: 85
I'm not very good at php so this should (hopefully) be easy for one of you.
I'm trying to send an HTML email from php which includes variables. I'm able to send a none html email with variables, or an HTML email without variables, but I can't seem to do both at the same time. Here's my code:
<?
$to = "[email protected]";
$from = "[email protected]";
$subject = "Hello! This is HTML email";
'
//begin of HTML message
$message = <<<EOF;
<html>
<p>Opt out of contact by phone<br />
'. $_POST["Opt_out_phone"] .'
</p>
</html> EOF;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo "Message has been sent....!"; ?>
I've never come across <<< EOF before and have no idea what it's doing.
Upvotes: 0
Views: 2266
Reputation: 11132
You're using HEREDOC syntax and attempting to terminate the string and append the variable incorrectly and unnecessarily. To declare your string with the variable, do this:
$message = <<<EOF;
<html>
<p>Opt out of contact by phone<br />
{$_POST["Opt_out_phone"]}
</p>
</html> EOF;
Note that the PHP manual entry on heredoc syntax is with the rest of the string docs, here.
Upvotes: 1