Jump to content

PHP mail function doesn't send html mail


harry_ord
 Share

Recommended Posts

Hello

 

I'm following w3schools' PHP tutorial and i'm trying to send an html mail:

http://www.w3schools.com/php/func_mail_mail.asp

But the HTML part of the mail doesn't work, i get my mail with all the html tags written literally, like this:

iPkUXZ.png

Is something missing?

 

This is my code:
<?php

$msg = "<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// send email
mail("felipepinoredes@gmail.com","Formulario Idea",$msg);
}
?>
Edited by harry_ord
Link to comment
Share on other sites

You have to add a Content-Type header to the e-mail.

$headers .= 'Content-Type: text/html' . "\r\n";

Then add the headers when sending the e-mail:

mail("felipepinoredes@gmail.com","Formulario Idea",$msg, $headers);
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...