php - export to CSV function not working properly -
php - export to CSV function not working properly -
idi have php script working though, outlook 2003 client receive plain text. 2007 , newer csv file received fine. has thought problem is?
secondly, possible send file xls-file also?
$random_hash = md5(date('r', time())); //$random_hashattachment = md5(date('r', time())); $csvstring = '"id","information"' . php_eol; $sql = mysql_query("select * table"); while($uitkomst = mysql_fetch_array($sql)) { $id = $uitkomst["id"]; $information = $uitkomst["information"]; $csvstring .= "\"$id\",\"$information\" " . php_eol; } file_put_contents('allprojects.csv', $csvstring); // write file $attachment = chunk_split(base64_encode($csvstring)); $to = "info@contoso.com"; $from = "info@me.com"; $subject = "subject"; $body = "this body text"; $headers = "from: $from\r\nreply-to: $from"; $headers .= "\ncontent-type: multipart/mixed; boundary=\"php-mixed-".$random_hash."\""; $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 " . $body . " --php-mixed-$random_hash content-type: text/csv; name=allprojects.csv content-transfer-encoding: base64 content-disposition: attachment $attachment --php-mixed-$random_hash--"; mail($to, $subject, $output, $headers);
php csv export
Comments
Post a Comment