Sending HTML email from php with variables

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 = "me@something.co.uk";
$from = "m2@something.com";
$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.

Answers


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.


Need Your Help

Mongodb concurrent map reduce

mongodb concurrency mapreduce

I have collection with events, indexed by time field. Can i run more then one incremental (with output merge to another collection) map-reduce job on it in parallel? (for example - on each five min...

What does `T {}` do in Scala

scala shapeless

Browsing Shapeless code, I came across this seemingly extraneous {} here and here: