Sending an HTML email from a PHP script

From Knowledge Kitchen
Jump to navigation Jump to search

This example sends an HTML email in PHP. The key difference between this and sending a plain text email is in the Content-Type header.

 $to = "Bob Johnson <>";
 $from = "";
 $fromName = "Barack Obama";
 $subject = "Yo Bob!";
 $message = <<<END
 		<h1>Hello from the President</h1>
 		<img style="float:right;" src="" />
 			Bacon ipsum dolor sit amet boudin rump beef ribs, ground round short ribs salami sirloin t-bone chuck venison pork belly pancetta turducken. Meatball prosciutto capicola, ball tip brisket pastrami ground round beef ribs tail rump meatloaf short loin pork chop. Shankle salami t-bone, andouille tenderloin ground round pork chuck. Kielbasa turkey biltong, tenderloin meatloaf boudin ham hock. Frankfurter short ribs flank, shank doner hamburger t-bone bacon.";
 $headers = <<<END
 From: {$fromName} <{$from}>
 Reply-to: {$from}
 X-Mailer: PHP/5
 MIME-Version: 1.0
 Content-Type: text/html; charset=utf-8
 mail($to, $subject, $message, $headers);

What links here