I’m using a mail function which is sending back a message that is contained within the variable $body. I want to send the message to myself with certain words in bold and a number of break tags.
Here is my code(HEREDOC SYNTAX):
$body = <<<CTS
<h1><b>Order for $name on datevariable</b></h1><br /><br />
<b><u>Administrative Details</u></b><br />
<b>Employee ID:</b> $id<br />
<b>Cost Center:</b> $cost_center<br />
<b>Approved By:</b> $approved_by<br />
<b>Delivery Bldg:</b> $delivery_bldg<br />
<b>Delivery Contact Email:</b> $delivery_contact<br />
<b>Ext:</b> $del_contact_ext<br />
CTS;
For some reason when I receive the email, it looks like this:
<h1><b>Order for James Important on datevariable</b></h1><br /><br />
<b><u>Administrative Details</u></b><br />
<b>Employee ID:</b> 213123<br />
<b>Cost Center:</b> 132123<br />
<b>Approved By:</b> Chris Seckla<br />
<b>Delivery Bldg:</b> 6<br />
<b>Delivery Contact Email:</b> test@email.com<br />
<b>Ext:</b> 56<br />
It fills in the variable values but for some reason ignores the html tags. Can someone please tell me how to fix this?
Also, it is ignoring the break tags and only putting breaks when I leave a line of whitespace. Any ideas on this?
If this is an email, you have to set the mime type to text/html instead of text/plain. Otherwise your email reader will interpret the message as plain text and ignore all the html tags.
For example, lets say you are calling the
mailfunction like this:In
$headers, you’d need something along these lines (adjusted for your particular case, of course):If you want to send both plain text and html email (so non-html readers can see a clean version of the email without all those tags), I would suggest taking a look at this tutorial for a more detailed explanation of multipart emails.