By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,309 Members | 1,596 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,309 IT Pros & Developers. It's quick & easy.

what's wrong with this MIME mail ?

P: n/a
hi all,

I have a script to send newsletters both in html and text version, all
works fine in email clients but unfortunately not in yahoo mail: it
shows nothing in the body of the message, however if I forward that
mail from yahoo I can see it perfectly again in outlook/eudora.
By some trial and errors I found that without the first 2 headers, it
works fine in yahoo mail too, so what's wrong with my headers ?

Thanks in advance to who can help me about that .

johnny

here's the code ( the relevant part )

// create boundary
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// HEADERS
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative;\n".
" boundary=\"{$mime_boundary}\"";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: me<me@mysite.com>\r\n";
$headers .= "X-Sender: me<me@mysite.com>\n";
$headers .= "Reply-To: me<me@mysite.com>\r\n";
$headers .= "Return-Path: me<me@mysite.com>\n";
$query = mysql_query("SELECT id, email FROM $table ", $db);

while ($to = mysql_fetch_array($query)) {

$recipient = $to[email];

$message_html = 'some HTML here ';

$message_text = ' some text here ';

// MESSAGE TO BE SENT

$message = "This is a MIME message \n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message_text."\n".
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message_html."\n".
"--{$mime_boundary}--\n";

@mail ($recipient, $subject, $message, $headers );
}
?>

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
johnny wrote:
[PHP-generated email not behaving in Yahoo mail]
Here are 2 things you could consider:

1. Use consistent line breaks in the email headers. At the moment you're
using a mixture of "\r\n", "\n", and "". For example:
$headers = "MIME-Version: 1.0\r\n"; // \r\n
$headers .= "Content-Type: multipart/alternative;\n". // \n
" boundary=\"{$mime_boundary}\""; // nothing!
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";


I heard some mail systems will only accept "\n", even though the standards
require "\r\n". Anyway, why are you switching to "\n" in the mail body?

2. Are you sure the content of the email is 7-bit clean? Maybe you need to
use quoted-printable encoding instead.

HTH,

Phil

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #2

P: n/a
hi phil,

it seems that using just /n and putting the MIME and content-type
headers after all the other ones works both with email clients and
webmail services.

I came to that after some trials and errors but it sounds to have some
logic to me.

thanks again

johnny

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.