Thursday, 25 June 2015

How to send HTML mail in PHP

How to send HTML mail in PHP

To send HTML mail in PHP, you need to use some additional headers. Below is the code to send HTML mail in PHP.
$to = “recipient@domain.com“;
$subject= “Subject of email”;
$message= “This is <h1>HTML</h1> mail.”;
$fromName = “Name of the sender”;
$fromEmail = “sender@domain.com“;
// To send HTML mail, the Content-type header must be set
$headers  = “MIME-Version: 1.0″ . “\r\n”;
$headers .= “Content-type: text/html; charset=iso-8859-1″ . “\r\n”;
// Additional headers
$headers .=”From: $fromName <$fromEmail>”.”\r\n”;
//Mail function
mail($to, $subject, $message, $headers);

No comments:

Post a Comment