Scott Hurring » Code » PHP » Send HTML Email

Download Code
download
html_email-v0.2.tgz
v0.2 · Apr 06, 2005

Problem

You want to send HTML email using PHP.

Solution

You need to give mail() some extra headers that will tell the mail client to interpret the email as HTML.

The headers are MIME-Version: 1.0 and Content-type: text/html; charset=iso-8859-1


Source Code


<?
/**
 * Send HTML email with PHP
 * This code will print out all key=>value pairs in an array
 * @author Scott Hurring - scott at hurring dot com
 * @license GPL
 *
 * http://hurring.com/code/php/
 *
 * $Id: html_email-v0.2.phps,v 1.1.1.1 2005/11/26 21:12:51 shurring Exp $
 */

$to "your@email.com";
$subject "Test email";
$body "This is the body<p>\nIt contains HTML<p>\n<ul>\n";
foreach (
$form as $k=>$v) {
        
$body .= "\t<li>$k = "stripslashes($v) ."<br>\n";
}
$body .= "</ul>\n";

$headers "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to$subject$body$headers);
?>


Download