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 apache@myhost.com... 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 <mary@example.com>, Kelly <kelly@example.com>' . "\r\n"; $headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n"; $headers .= 'Cc: birthdayarchive@example.com' . "\r\n"; $headers .= 'Bcc: birthdaycheck@example.com' . "\r\n"; print "<pre>"; if ($_POST) { mail($to, $subject, $message, $headers); } print "</pre>"; ?> Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment 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'] Quote Link to comment 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@email.com'; 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.