The code below is sending an email correctly but for the body. I need to show html in the body of the message and I cannot make it. The examples in the web won't send the email :(
How can I fix my code to send the email with the html in the body?
Thanks a ton!
<?php
$to = 'mymail@mail.com';
$subject = 'I need to show html';
$from ='example@example.com';
$body = '<p style=color:red;>This text should be red</p>';
ini_set("sendmail_from", $from);
$headers = "From: " . $from . "\r\nReply-To: " . $from . "";
$headers .= "Content-type: text/html\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Sent</p>");
} else {
echo("<p>Error...</p>");
}
?>
I found this works well!
Source
use this header for the mail:
and for the content/body:
it's important to use inline css commands and recommanded to use tables for the interface.
...
In your Mail-Body you than have to put HTML code with head and body
Simple answer: Don't do it. HTML emails are evil and annoying. At least if there's no PROPER plaintext version included. Proper = same information like in the HTML version, not just a stupid comment about getting another email client or a link to the html version if it's available on the web.
If you really need it: http://pear.php.net/package/Mail_Mime
Have you looked at the headers of the incoming mail? It says
Simply add another
\r\n
here:I recommend rather than messing around with doing this yourself you use one of the many free classes available all over the web to do it.
I would recommend: PHPMailer