cancel
Showing results for 
Search instead for 
Did you mean: 

PHP multipart mail not showing on Mac's

mar7t1n
Grafter
Posts: 93
Thanks: 5
Registered: ‎09-08-2007

PHP multipart mail not showing on Mac's

I'm sending some emails from PHP -
mail($to, $subject, $emailbody, $headers);
using a multipart, and most PC boys are fine, but it seems everyone using a Mac says nope can't see a thing stop sending me blank emails. So looking for anyone who's done this and got it working. The $emailbody is:
YOUR EMAIL READER DOES NOT SUPPORT MULTI-PART DOCUMENTS
BLAH BALH BLAH
--PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
YOUR EMAIL READER DOES NOT SUPPORT HTML DOCUMENTS
BLAH BALH BLAH
--PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Here's a nice HTML document
<BR><BR> So good that you can read it properly.
--PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY

And the header is:
Content-Type: multipart/alternative; boundary="PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY"
MIME-Version: 1.0
X-Mailer: PHP v4.3.9
From: Martin <martin@thisismartin.co.uk>

So what have I done wrong or is it just a few old Mac who's will never be able to read anything?
3 REPLIES 3
Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: PHP multipart mail not showing on Mac's

Mail is finicky. Have you tried it with a final -- (double hyphen, no space) after the last boundary?
Gabe
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: PHP multipart mail not showing on Mac's

IIRC you need to have some extra headers, along the lines of:

MIME-version: 1.0
Content-type: multipart/alternative;
boundary=--PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY

Although personally I think HTML email is evil, different strokes for different folks I guess Smiley
mar7t1n
Grafter
Posts: 93
Thanks: 5
Registered: ‎09-08-2007

Re: PHP multipart mail not showing on Mac's

Hi Gabe,
After much fiddling I stumbled across the requirement to have a double hypen (--) at the end of the last boundaray statement. Thanks to gmail.com which was also as picky as the Mac users and now everyone can read all that I send them  Smiley
--PHP-alt-THISISMARTINLIVEBOOKINGCONTENTBOUNDARY--

I'm also sending the message in plain text so that all those can't / won't read HTML can still get the jist of what we're saying.
$plaintext = ereg_replace ("<([^<>]*)>", "", $plaintext );
$plaintext = ereg_replace ("&pound;", "GBP ", $plaintext );
$plaintext = ereg_replace ("[\t]*","",$plaintext);
$plaintext = ereg_replace ("\r[ \t\r\n\v\f]*\r","\r\n",$plaintext);

So all solved.... Onto the next problem now....