Kane250 Posted May 6, 2008 Share Posted May 6, 2008 Anyone familiar with mail() ? I'm using it to build an email app. I'm using an ajax text editor that allows for test editing (color, bold, fnt, etc.) and it sends it all as html to mail(). However the e-mails that I receive all come with the actual html code written inside it. I added all the headers that it looked like I needed, but yet it still refuses. Anyone? Oh also, if anyone has information about changing the envelope from name, I'm having a tough time there too. Keeps coming in as [email protected]... Thanks! <?php $to = $_POST['to']; $subject = $_POST['subject']; $message = $_POST['msgpost']; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: Mary <[email protected]>, Kelly <[email protected]>' . "\r\n"; $headers .= 'From: Birthday Reminder <[email protected]>' . "\r\n"; $headers .= 'Cc: [email protected]' . "\r\n"; $headers .= 'Bcc: [email protected]' . "\r\n"; print "<pre>"; if ($_POST) { mail($to, $subject, $message, $headers); } print "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/104308-solved-mail-continues-to-send-html-code/ Share on other sites More sharing options...
atravotum Posted May 6, 2008 Share Posted May 6, 2008 Hmm I wish I had a direct answer for you, however I do have a far fetched idea. When I was coding the mail function I had this... $to = $_POST["to"]; $from = $_POST["from"] . "\r\n"; $subject = $_POST["subject"]; $message = $_POST["message"]; $headers = "From: $from"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$message,$headers); The only difference in our two scripts is I create the mime, and content type last, you pile stuff on after it. Try calling that last and see what you get, just a thought. Link to comment https://forums.phpfreaks.com/topic/104308-solved-mail-continues-to-send-html-code/#findComment-534090 Share on other sites More sharing options...
Kane250 Posted May 6, 2008 Author Share Posted May 6, 2008 Nope, it just places it after the other headers in the email and then has the same html code... Thanks though! Link to comment https://forums.phpfreaks.com/topic/104308-solved-mail-continues-to-send-html-code/#findComment-534100 Share on other sites More sharing options...
Fadion Posted May 6, 2008 Share Posted May 6, 2008 If the from name is a variable, it should be enclosed in double quotes or concatenated when used on the $headers variable. Place also an X-Mailer: PHP/" . phpversion() in the headers so clients identify it as an automated email sent from a php script. As for the html issue, im throwing something nosense here, use htmlentities() on $_POST['message'] Link to comment https://forums.phpfreaks.com/topic/104308-solved-mail-continues-to-send-html-code/#findComment-534106 Share on other sites More sharing options...
Kane250 Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks. I found a fix by changing the code to this: <?php $to = $_POST['to']; $subject = $_POST['subject']; $message = $_POST['msgpost']; $from = '[email protected]'; print "<pre>"; if ($_POST) { mail($to, $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1"); } print "</pre>"; ?> It seems to work, although not all the html formatting is coming through to the emails. Color, underline, etc. doesn't work. Link to comment https://forums.phpfreaks.com/topic/104308-solved-mail-continues-to-send-html-code/#findComment-534117 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.