homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
mail() sending blank message? help?
php mail() no message
jezzer300

10+ Year Member



 
Msg#: 4947 posted 5:19 pm on Sep 2, 2004 (gmt 0)

Hi,

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]

 

Knowles

10+ Year Member



 
Msg#: 4947 posted 5:26 pm on Sep 2, 2004 (gmt 0)

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?

jezzer300

10+ Year Member



 
Msg#: 4947 posted 5:34 pm on Sep 2, 2004 (gmt 0)

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).

Knowles

10+ Year Member



 
Msg#: 4947 posted 7:04 pm on Sep 2, 2004 (gmt 0)

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

Nikke

10+ Year Member



 
Msg#: 4947 posted 10:19 pm on Sep 2, 2004 (gmt 0)

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

mail("$mailto","$subject","$message","$headers");

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved