Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending HTML formatted email

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
I have been having trouble lately with a form that sends HTML formatted emails. Some people receive the email correctly, while most get a text email with all the HTML tags showing. It makes it really hard to read.

Why do some get the email fine, while others don't?

Here is the code. I pull the To, Subject, and Message from a form (not included - ask and I'll post it). This is the PHP part.

Code:
    $toText = $_POST['toText'];
    $msgText = $_POST['msgText'];
    $subjectText = $_POST['subjectText'];

    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "From: My Email <me@site.com>\r\n";

    $headers = str_replace("\r", "\n",   $headers);
    $headers = str_replace("\n\n", "\n", $headers);
    $headers = str_replace("\n", "\r\n", $headers);

    $msgText = stripslashes($msgText);

    mail($toText, $subjectText, $msgText, $headers);

Do I need to have something first - before the MIME-Version line in the headers part? Or is there something I'm missing with the mail() function.

Any help or suggestions is appreciated.

Einstein47
“Evil abounds when good men do nothing.“ - Nelson R.
[&#91;]Starbase47.com]
 
use multipart mail and send a text and an html version. you can either do this manually (see the FAQ) or use phpmailer() from sourceforge. i'd recommend the latter for an easy life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top