Inspiration For Creative Minds
Home » Labs » How to send html email with PHP – solved  

Filed under Labs

If you are a developer and using PHP for development then in some projects you need to create email functions according to client requirement. You can send simple emails by using default mail function of PHP. Here is a piece of code which allows you to send HTML mail with proper usage of extra headers. This will give more flexibility so you can attach files format it in HTML and many more.

 
<?php 
 
	$to   = "user@userdomain.com";
	$from = 'admin@vishmax.com';
 
	$headers = "From: " . strip_tags($from) . "\r\n";
	$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
	$headers .= "CC: admin@vishmax.com\r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
 
	$message = '<html><body>';
	$message .= '<table width="100%"; rules="all" style="border:1px solid #3A5896;" cellpadding="10">';
	$message .= "<tr><td colspan=2>Hello \$Name,<br /><br />Expand the message part according to your design layout</td></tr>";
	$message .= "</table>";
	$message .= "</body></html>";
 
	mail($to, $subject, $message, $headers);
 
?>
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook
Labs

Posts you may like: