php mail() attachments down under

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

php mail() attachments down under

Post by paqman »

I'm developing a website for an Australian client and one of its features is that it sends emails with a file attached automatically when someone signs up for his service. The problem I'm running into is that in North America the emails are coming through no problem. The main body is beautiful html and the attachment works perfectly. However, where it really counts, in Australia, the email comes through like this:

Code: Select all

 
Content-Type: text/html; charset=iso-8859-1
 
Content-Transfer-Encoding: 7bit
 
 
 
<p><strong>Here</strong> is your custom report on what you wanted.</p>
 
 
 
 
Content-Type: application/octet-stream; name="Report 1.jpg"
 
Content-Transfer-Encoding: base64
 
Content-Disposition: attachment; filename="Report 1.jpg"
 
 
 
/9j/4AAQSkZJRgABAgEAYABgAAD/7ABzRHVja3kAAQAEAAAAPAADAF4AAAAtACgAYwApACAASwBl
 
AHYAaQBuACAARgBvAHIAZQBzAHQALwBQAGgAbwB0AG8AZABpAHMAYwAgAEcAcgBlAGUAbgAvAEcA
 
ZQB0AHQAeQAgAEkAbQBhAGcAZQBzAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRy
 
UkdCIFhZWiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYA
 
AQAAAADTLUhQICAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 
ABFjcHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaAAAC
So, as you can see, it's like its treating the whole email as plain text, and ignoring all headers. They have tried Outlook, Outlook Express, their online webmail, etc, for a variety of accounts. Here is my php doing the attaching/mailing:

Code: Select all

 
//$fr is the mysql array for the report to be emailed
//$fde is a config mysql entry
 
                                    $file = $path.$fr["fileid"];
                                    $file_size = filesize($file);
                    $handle = fopen($file, "r");
                    $content = fread($handle, $file_size);
                    fclose($handle);
                    $content = chunk_split(base64_encode($content));
                    $uid = md5(uniqid(time()));
                    $name = basename($file);
                    $header = "From: Trading Sykology <".$fde["value"].">\r\n";
                    $header .= "Bcc: ".$fde["value"]."\r\n";
                    $header .= "MIME-Version: 1.0\r\n";
                    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
                    $header .= "This is a multi-part message in MIME format.\r\n";
                    $header .= "--".$uid."\r\n";
                    $header .= "Content-Type: text/html; charset=iso-8859-1\r\n";
                    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
                    $header .= html_entity_decode($fr["message"])."\r\n\r\n";
                    $header .= "--".$uid."\r\n";
                    $header .= "Content-Type: application/octet-stream; name=\"".$fr["fileid"]."\"\r\n"; // use diff. tyoes here
                    $header .= "Content-Transfer-Encoding: base64\r\n";
                    $header .= "Content-Disposition: attachment; filename=\"".$fr["fileid"]."\"\r\n\r\n";
                    $header .= $content."\r\n\r\n";
                    $header .= "--".$uid."--";
                    if (mail($t_first." ".$t_last." <".$t_email.">", $fr["name"], "", $header)) 
                    {
                        echo $fr["name"]." was sent successfully.<br>";
                    } 
                    else 
                    {
                        echo $fr["name"]." could not be sent.<br>";
                    }
 
I'm really stumped - any help would be greatly appreciated!
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: php mail() attachments down under

Post by Syntac »

There are some user-contributed notes here. Not sure how helpful they'll be, though.
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: php mail() attachments down under

Post by mmj »

If its going through fine to North America then I doubt its a problem on the sending end, most probably a problem on the receiving end.

What are you sending it to? Another POP3 server or one of the popular free email sites?
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: php mail() attachments down under

Post by paqman »

It's going to a variety of email servers... I'm starting to think I should just try the PEAR mail package.
Post Reply