View Full Version : HTML email???

06-12-2007, 11:53 AM
in PHP normal mail function

mail($to, $subject, $body)
can I use HTML body which contains
<a href="link">some text </a>codes like.......

will the mail be sent as HTML??

if not what should i do to send HTML mail??? any body can help me??

06-12-2007, 11:59 AM
The mail() function accepts 4 items. The to email address, the subject, the message, and the headers. If you don't specify the headers the default is text/plain. Put this before you call the mail() function

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: you@domain.com\r\n" .
"Reply-To: ".$to."";
Then you call the mail() function like so

mail($to, $subject, $body,$headers)

06-12-2007, 04:59 PM
Another tip for html email, use heredoc syntax (http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) to build the html of the message. Heredoc behaves like double quotes without having to actually use them. Very handy for html tags with lots of attributes...