3

Possible Duplicate:
Sending HTML email from PHP

Using PHP to send an email.

I want it to be HTML based but when I get the email in my inbox it just shows the raw code.

How can I make it interprited as HTML rather then just text?!

For everyone asking to see the code

<?php
//The email of the sender
$email = $_POST['email'];
//The message of the sender
$message = "<html></html>";
//The subject of the email
$subject = "Fanshawe Student Success";
$extra = $email."\r\nReply-To: ".$email."\r\n";
mail($email,$subject,$message,$extra);
?>
Community
  • 1
  • 1
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

2 Answers2

7

from the docs: http://php.net/manual/en/function.mail.php

$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

obviously $headers has to be passed to the mail

Tim Hoolihan
  • 12,316
  • 3
  • 41
  • 54
5

here you go:

// multiple recipients
$to  = 'someemail@address.com';

//subject
$subject = 'Email Template for Lazy People';

//message body
$message = "
<html>
<head>
  <title>My Title</title>
</head>
<body>
    <div>
        <b>My email body</b>
    </div>
</body>
</html>
";

//add headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: yourself<info@yourself.com>' . "\r\n";
$headers .= 'From: myself<info@myself.com>' . "\r\n";

//send mail
mail($to, $subject, $message, $headers);
Ricardo
  • 173
  • 7
  • Thanks all, Our Prof. never went over headers when we went over mailscripts so it was not so obvious for me. But greatly Appreciated! – Philip Kirkbride Jul 28 '11 at 14:47