Forum Moderators: coopster

Message Too Old, No Replies

mail() sent works but HTML not parsed in email

<html> codes show up in the email instead of being interpreted.

         

WestCoGuy

8:28 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



I have a .php HTML document with the following PHP script included. This code works and sends the email. But the email does not show up as HTML email, but instead shows the <html><body>, etc. code. Not sure what's wrong.

<script language="php">

$item1 = "A brown tree stump.";
$item2 = "Apples.";
$item3 = "Just a wagon.";

$recipient = "Receiver@Address.com";
$subject = "Test HTML email";
$sender = "Sender@Address.com";
$mailheader = "From: $sender\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$message = "<html>\r\n";
$message .= "<head>\r\n<title>$subject</title>\r\n</head>\r\n<body>\r\n";
$message .= "<font face=\"Courier New\" size=\"2\">";
$message .= "The brown item is: $item1\r\n";
$message .= "The two red items are: $item2\r\n";
$message .= "The third item is: $item3\r\n";
$message .= "</font>\r\n</body>\r\n";
$message .= "</html>\r\n";

mail($recipient, $subject, $message, $mailheader) or die ("Failure");

</script>

I RECEIVE THE FOLLOWING EMAIL BODY:

Content-type: text/html; charset=iso-8859-1

<html>
<head>
<title>Test HTML email</title>
</head>
<body>
<font face="Courier New" size="2">The brown item is: A brown tree stump.
The two red items are: Apples.
The third item is: Just a wagon.
</font>
</body>
</html>

WestCoGuy

11:13 pm on Jan 25, 2004 (gmt 0)

10+ Year Member



Fixed my own problem. Now I can send HTML email properly. I Just removed:

$mailheader .= "MIME-Version: 1.0\r\n";

But I don't know what that line is supposed to help me with. Where I'm really going with this is to create RTF email, not HTML email.

Timotheos

6:50 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's weird. I have something like this which works fine.

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "From: Tim <me@example.com>\r\n";

Maybe the order matters?

slartibartfaster

4:01 am on Jan 28, 2004 (gmt 0)



WestCoGuy,
Removing the "Mime-Version" line worked for me but I get unsuppressed header info at the top of my beautifully HTML formatted message...

To: IT-Staff From: File_Submission_Utility Message-Id: <20040128035030.************@sauron.xxxxxxxx.qld.edu.au> Date: Wed, 28 Jan 2004 13:50:30 +1000 (EST) Return-Path: File_Submission_Utility@sauron.xxxxxxxx.qld.edu.au X-OriginalArrivalTime: 28 Jan 2004 03:50:30.0799 (UTC) FILETIME=[DFE5B1F0:01C3E551]

Any ideas on how to keep this stuff out of the message body?