Send HTML Email with PHP and mail()

The PHP mail() function is great for sending plain text emails but it will not send HTML emails without special headers.

Here is a PHP mail() with HTML example:

$body_html = '
	<html>
		<head>
			<title>HTML Test Email</title>
			<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		</head>
		<body>
			<p>
				This is a test.
			</p>
		</body>
	</html>
';

$from = 'sender@example.com';
$to = 'recipient@example.com';
$subject = 'HTML Test Email';
$headers = "From:$from\n" .
    "MIME-Version: 1.0\n" .
    "Content-type: text/html; charset=iso-8859-1";

mail($to, $subject, $body_html, $headers);

Demo

Demo Send HTML Email with PHP and mail()

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

Related Posts

  • No Related Post

Comments (2)

  1. Jeremy says:

    Is this part necessary? mail($to, $subject, $body_html, $headers);

  2. Without the mail function the email will not be sent.

Leave a Reply





Donate

If you found this article useful and would like to see more like it this please consider making a donation.

Sponsors