Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

mail() sending blank message? help?

php mail() no message



5:19 pm on Sep 2, 2004 (gmt 0)

10+ Year Member


Can you help, I'm going around in circles here...

I'm running PHP 4.3.8 on a Windows XP box.

I can sucessfully send myself HTML emails using the code below... ($message is a load of HTML script)

$headers = "";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO 8859-1\n";
$headers .= "From: test@example.co.uk<test@example.co.uk>\n";
mail( "test@example.co.uk", "Order Confirmation",$message, $headers );

But when I try to get clever with the headers to give a text alternative to HTML all I get is an email with a blank message, any idea why... the problem code is below...

$boundary = uniqid("DS"); //unique boundary
$headers .= "From: test@example.co.uk<test@example.co.uk>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\n\n";
$headers .= "This is a MIME encoded message.\n\n"; //message to people with clients who don't understand MIME
$headers .= "--$boundary\nContent-Type: text/plain; charset=ISO-8859-1\n";
$headers .="Content-Transfer-Encoding: 7bit\n\n";
$headers .= "Delphi Solutions Invoice";
$headers .= "--$boundary\nContent-Type: text/html; charset=ISO-8859-1\n";
$headers .="Content-Transfer-Encoding: 7bit\n\n";
$headers .= $message;
$headers .= "--$boundary--";
mail( "test@example.co.uk", "Order Confirmation","", $headers );

(p.s. I know I should use base64_encode() for the content transfer encoding once I get the script working. Also, I tried using /r/n, but that doesn't work even with my basic message under windows. I have based this code on several examples I've seen around on the internet)

[edited by: coopster at 6:35 pm (utc) on Sep. 2, 2004]
[edit reason] examplified URL per TOS [webmasterworld.com] [/edit]


5:26 pm on Sep 2, 2004 (gmt 0)

10+ Year Member

I think your $message still needs to be in the mail() function like it was in the first script. Do you get the title or anything of that nature?


5:34 pm on Sep 2, 2004 (gmt 0)

10+ Year Member

I get the "subject", but nothing else.

i've seen several examples on the internet, including one from zend and they all have a blank message in mail() and place the message in the header text, I assume this is to allow the multipart message.

Also, while I'm on the subject do you know what I specify if I want a response sent back when an email fails to arrive (bounces).


7:04 pm on Sep 2, 2004 (gmt 0)

10+ Year Member

Never seen that before but I have never gotten fancy with the mail function either. Text emails are all I need.


10:19 pm on Sep 2, 2004 (gmt 0)

10+ Year Member

Knowles is right.

mail( "test@example.co.uk", "Order Confirmation","", $headers );

I send a few thousand html with text newsletters each week and even though I use pretty much the same setup as your script I always send it off with


My headers end with:
$headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/alternative; \n\tboundary=\"This_is_my_unique_boundary_\"\r\nContent-Type: text/html; charset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: 8bit\r\n";
$headers = $headers."X-Mailer: My Hip php mailer v 3.0.1";

In the first line of my messages you put the separator to show that this is where the first part of the mail goes:
$message = "--This_is_my_unique_boundary_\r\nContent-Type: text/plain; charset=iso-8859-1\r\nContent-Transfer-Enoding: 8bit\r\n\r\n";

Hope it explains anything...
Do check the full source code of a working html mail with text part. That will pretty much tell you what to do yourself.


Featured Threads

Hot Threads This Week

Hot Threads This Month