13Apr

How to send html email with php

Posted by Duncan Mwangi as PHP

Below is a small snippet for sending html email.


<?
 //set email addresses below.
 $to = "to@to.com";
 $from = "from@from.com";
 $subject = "my subject";
 $cc = "cc@cc.com";
 $bcc = "bcc@bcc.com";
 //begin of HTML message
 $msg = "<html>
 <body>
 <div>
 <b>Click</b>
 <a href=\"http://www.clickhere.com/\">here</a>
 </div>
 <br><br>Thank you <br> Regards<br>Sender
 </body>
 </html>";
 //set the MIME-Version
 $headers = "MIME-Version: 1.0rn";
 //to send a html email change content-type as below
 $headers .= "Content-type: text/html; charset=iso-8859-1rn";
 //include from whom the email is being sent
 $headers .= "From: $from\r\n";
 //these are optional header parts i.e. Reply-To, cc and bcc
 $headers .= "Reply-To: $from \r\n" .
 $headers .= "Cc: $cc \r\n";
 $headers .= "Bcc: $bcc \r\n";
 //send the email below.
 if(mail($to, $subject, $msg, $headers)){
 echo "Email has been sent....!";
 }
 else{
 echo "Email was not sent....!";
 }
?>
Get a Free Quote at Twigahost.com