Jump to content

[SOLVED] Mail() continues to send html code


Kane250

Recommended Posts

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>";
?>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.