Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Generated CSV attachment seems to lose part of first line via Outlook but not Gmail
    text
    copied!<p>I have a PHP script running via cron under FreeBSD 8.0, sendmail, PHP 5.2.11 (cli).</p> <p>The first row of the CSV is defined by this line:</p> <pre><code>$content .= "\n" . 'first_name,last_name,address1,address2,city,state_province,postal_code,country' . "\n"; </code></pre> <p>Prior to a move to the current server this script worked fine however now it has an glitch:</p> <p>If the email is received via Outlook the first line looks like this in Excel:</p> <pre><code>ate_province postal_code country </code></pre> <p>and this in a text editor:</p> <pre><code>ate_province,postal_code,country </code></pre> <p>I added an extra "\n" to the beginning and saw it added one character to the abridged string so I tried added 31 and sure enough Outlook, my text editor, and Excel see a perfect file.</p> <p>Then I logged into Gmail and downloaded what should be the exact same file as it is the exact same email. I open it in Excel and my text editor and what should I find but 31 newlines...</p> <p>Anyone have any advice on what is happening?</p> <p>// Per request link to email with headers <a href="http://pastebin.com/wuyVf9HP" rel="nofollow">http://pastebin.com/wuyVf9HP</a></p> <p>// EDIT adding whole mail routine per XzKto's request</p> <pre><code>if (fwrite($handle, $content) === FALSE) { die("Cannot write to file ($filename)"); } $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: xxxx &lt;tourism@xxx.org&gt;\r\nReply-To: tourism@xxx.org\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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload