what's wrong with this MIME mail ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnny

    #1

    what's wrong with this MIME mail ?

    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_Bo undary_x{$semi_ rand}x";

    // HEADERS
    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: multipart/alternative;\n" .
    " boundary=\"{$mi me_boundary}\"" ;
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: me<me@mysite.co m>\r\n";
    $headers .= "X-Sender: me<me@mysite.co m>\n";
    $headers .= "Reply-To: me<me@mysite.co m>\r\n";
    $headers .= "Return-Path: me<me@mysite.co m>\n";


    $query = mysql_query("SE LECT id, email FROM $table ", $db);

    while ($to = mysql_fetch_arr ay($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 );
    }
    ?>

  • Philip Ronan

    #2
    Re: what's wrong with this MIME mail ?

    johnny wrote:
    [color=blue]
    > [PHP-generated email not behaving in Yahoo mail][/color]

    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:
    [color=blue]
    > $headers = "MIME-Version: 1.0\r\n"; // \r\n
    > $headers .= "Content-Type: multipart/alternative;\n" . // \n
    > " boundary=\"{$mi me_boundary}\"" ; // nothing!
    > $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";[/color]

    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.ne t/phil.ronan/


    Comment

    • johnny

      #3
      Re: what's wrong with this MIME mail ?

      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

      Comment

      Working...