Last updated on November 17th, 2015 at 06:35 am

There are two varieties of email. Text and HTML. Text email is like regular text messages. HTML email is like viewing a webpage with colors and images. To create the effect of an HTML email, a couple of extra headers must be added.

$to = "[email protected]";
$subject = "My HTML email test.";
$headers = "From: [email protected];\r\n";
$headers .= "Reply-To: [email protected];\r\n";
$headers .= "Return-Path: [email protected];\r\n";
$headers .= "MIME-Version: 1.0;\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message .= "<h1> This is a test </h1>";
$message .= "";

if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}

MIME stands for Multipurpose Internet Mail Extensions. It is a set of instructions that allows emails to be sent in more than just plain text.

Content-Type sets what type of data is goign to be sent. The default value would be “text/plain”.

Charset is character set. Each language or set of characters has its own title or name. This value lets the recipient email know which one is used to display the body message.

One thought on “HTML email PHP tutorial”

Leave a Reply

Your email address will not be published. Required fields are marked *