BeWebmaster

Sending HTML emails with PHP

Ad

Sending HTML emails using PHP is very simple. To send emails we use php mail(); function. When it comes to sending an HTML email we need to modify mail headers content-type to text/html.

This tutorial assumes you are creating a contact form for your website.

First create a form that your website visitors  will use to send you email. Try out tutorial "Create Simple Cross-Browser Textarea" to create a form with a simple HTML editor and customize it to use the script below.

sendemail.php

<?php
// get form variables
$to = "info @ yourdomain.com" ; //specify email address that will receive the email
$from = $_REQUEST['from'] ;
$subject = $_REQUEST['subject'] ;
$MSG = $_REQUEST['content'] ;

//now we need to set mail headers
$headers = "MIME-Version: 1.0 rn" ;
$headers .= "Content-Type: text/html; rn" ;
$headers .= "From: $from  rn" ;

//now we are ready to send mail
mail($to, $subject, $MSG, $headers);

?>