php mail() attachments down under
Posted: Sat Nov 01, 2008 1:39 pm
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:
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:
I'm really stumped - any help would be greatly appreciated!
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
ABFjcHJ0AAABUAAAADNkZXNjAAABhAAAAGx3dHB0AAAB8AAAABRia3B0AAACBAAAABRyWFlaAAACCode: 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>";
}