phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Email: Sending a Simple HTML Mail (Part 2)

Tag: email   Category: PHP Basic
post: 18 Nov 2007 read: 2,536


May be you ever get advertise email. They send you a html email. The layout is very nice. There are many tables, coloring font, and soon. Yeah, they use html mail. They just set the body of the email to have HTML in it and add one additional header of Content-type: text/html and have it work. Ok, look the code:


 <?php
// Setting a timezone, mail() uses this.
date_default_timezone_set('America/New_York');
// recipients
$to  = "you@phpeveryday.com" . ", " ; // note the comma 
$to .= "we@phpeveryday.com"; 

// subject
$subject = "Test for HTML Format"; 

// To send HTML mail, you can set the Content-type header. 
$headers  = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

// additional headers
$headers .= "To: You <you@phpeveryday.com>, 
We <we@phpeveryday.com>\r\n"; 
$headers .= "From: Me \r\n"; 
$headers .= "Cc: he@phpeveryday.com\r\n"; 
$headers .= "Bcc: she@phpeveryday.com\r\n";

// Your message here:
$body = "
<html>
<head>
<title>Test HTML Mail</title>
</head>
<body>
<font color='red'>Hai</font>
</body>
</html>
";

// Finally, send the email
mail($to, $subject, $body, $headers);
?>


Series this article:
Email: Sending a Simple Email (Part 1)
Email: Sending a Simple HTML Mail (Part 2)
Email: Sending Dual Format (Part 3)
Email: Send Attachement Mail
PHP Email: Using Embedded Images in HTML Email
PHP Email: Sending Mass Email use BCC
PHP Email: Protecting Email Address from Spam Collectors

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting