views:

181

answers:

1

Hi folks,

The code below has been sending CSVs to our print fulfillment folks for years. Beginning of the week the sysadmin switched from sendmail to qmail for reasons having to do with procmail recipes we want to run.

Probably not coincidentally we starting started hearing that the fulfillment folks were seeing empty CSVs even when others CCed on the mail saw the records. Folks with the issue were seeing the attachment and could open it but their MUI was listing it as 131 bytes or zero bytes.

We started sending to a Yahoo address with same results. However Gmail sees attachment with correct rows. Mind you this is all one CCed email with different results depending on mail clients.

I have gone over the code in vi and made sure there were no ^M chars or other control character junk.

Anyone seen this before? Any suggestions most welcome!

Thanks!

JG

$message = "Here is the file (comma-separated values) of addresses for\n";
$message .= $pm_row['title'] . " Requests ($now_YmdHMS).\n\n";
$data_email = $pm_row['fulfillment_data_email'];
$data_email_cc = "$pm_row[fulfillment_data_email_cc],$developer_email";
$subject = $pm_row['title'] . " Requests ($now_YmdHMS)";
$random_hash = md5(date('r', time()));
$headers = "From: XXX <[email protected]>\r\nReply-To: [email protected]\r\nCc:$data_email_cc"; 
$headers .= "\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$output = "
--PHP-mixed-$random_hash; 
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
--PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit

$message

--PHP-alt-$random_hash 
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit

$message

--PHP-alt-$random_hash--

--PHP-mixed-$random_hash
Content-Type: application/zip; name=$now_YmdHMS.$pm_row[handle].csv
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

$attachment
--PHP-mixed-$random_hash--";

mail($data_email, $subject, $output, $headers);
+1  A: 

I think it is a CR/LF problem, which is a known Bug in php for about three years and -as far as I know- hasn't been fixed up to now:

http://bugs.php.net/bug.php?id=15841

The generated Email isn't valid (explanation can be found here: http://cr.yp.to/docs/smtplf.html ), due to using a non-RFC-conform linebreak-format. Other MTA like sendmail and postfix correct this problem automatically; qmail doesn't.

You can either: write correct mails with php (lol), or ask your qmail-administrator to use the QmailScanner ( http://qmail-scanner.sourceforge.net/ ), which is doing this job too.

The best solution would be to deinstall php and use perl in the future duck ;)

Erik
I'm originally a Perl man myself. When Perl is your hammer the world looks like, well, the world. Thanks for the links and the information!
jerrygarciuh