PDA

View Full Version : sending email from php with html format


pc
2011-02-25, 04:55 PM
$message gets content from textarea and it looks like this

<a href="http://www.domain.com">LINK</a> text text text <a href="http://www.domain.com">ANOTHER LINK</a> <a href="http://www.domain.com">IMG SRC</a> more text<?php

$mailTo = $_POST['emailTo'];
$mailFrom = $_POST['emailFrom\r\n'];
$subject = $_POST['subject'];
$message = $_POST['message'];

/* To send HTML mail, you can set the Content-type header. */
$headers = "From: emailFrom\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($mailTo, $subject, $message, "From: ".$mailFrom, $headers);
?>

I'm scratching my head and can't figure it out, still have text emails.

pc
2011-02-25, 10:38 PM
Well, I had it almost right, following solution works perfect :)

<?php

$mailTo = $_POST['emailTo'];
$mailFrom = $_POST['emailFrom\r\n'];
$subject = $_POST['subject'];
$message = $_POST['message'];

/* To send HTML mail, you can set the Content-type header. */
$headers = "From: emailFrom\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

mail($mailTo, $subject, $message, $headers, "From: ".$mailFrom);
?>

Sometimes I hear a ring, just don't know where exactly.