Excel Attachment sent via php mail() is corrupted -


am using below code send excel file attachment.

<?php  ini_set ("smtp","smtp.smpt.com"); ini_set ("sendmail_from","from.com"); $date=date("l js \of f y"); $to  = 'my mail id';  $from = 'from mail id';  $replyto  = 'from mail id';  $fileatt="zxxxxxyyyyyy.xls"; $subject = 'tran data rejects of ' .$date;  $message= "hi team, please find attached file having tran data rejects of today thanks,     edw support";      $flags = 'style="display:none;"';      $attachment = chunk_split(base64_encode(file_get_contents($fileatt)));      $filename = $fileatt;      $boundary =md5(date('r', time()));       $headers = "from: mail\r\nreply-to: mail";      $headers .= "\r\nmime-version: 1.0\r\ncontent-type: multipart/mixed;     boundary=\"_1_$boundary\"";          $message="this multi-part message in mime format. --_1_$boundary content-type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary content-type: text/plain; charset=\"iso-8859-1\" content-transfer-encoding: 7bit $message --_2_$boundary-- --_1_$boundary content-type: application/vnd.ms-excel; name=\"$filename\"  content-transfer-encoding: binary content-disposition: attachment  $attachment --_1_$boundary--";      mail($to, $subject, $message, $headers); ?> 

the problem attachment receive in mail corrupted below--

content-transfer-encoding: binary content-disposition: attachment   0m8r4kgxgueaaaaaaaaaaaaaaaaaaaaapgadap7/cqagaaaaaaaaaaaaaaabaaaaaqaaaaaaaaaa eaaawgaaaaeaaad+////aaaaaaaaaad///////////////////////////////////////////// ////////////////////////////////////////////////////////////9 ////wqaaaamaaaaeaaaabqaaaayaaaahaaaacaaaaakaaaakaaaacwaaaawaaaanaaaadgaaaa8a aaaqaaaaeqaaabiaaaataaaafaaaabuaaaawaaaafwaaabgaaaazaaaaggaaabsaaaacaaaahqaa ab4aaaafaaaaiaaaaceaaaaiaaaaiwaaacqaaaalaaaajgaaaccaaaaoaaaakqaaacoaaaaraaaa laaaac0aaaauaaaalwaaadaaaaaxaaaamgaaadmaaaa0aaaanqaaadyaaaa3aaaaoaaaadkaaaa6 aaaaowaaadwaaaa9aaaapgaaad8aaabaaaaaqqaaaeiaaabdaaaaraaaaeuaaabgaaaarwaaaega aabjaaaasgaaaesaaabmaaaatqaaae4aaabpaaaauaaaafeaaabsaaaauwaaafqaaabvaaaavgaa 

can guys me correct code :(

try use mail_attachment function

$mypath = path excel file

$headers  = 'mime-version: 1.0' . "\r\n"; $headers.= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; // , addition code here mail_attachment($email_from, $email_to, $email_subject, $email_message ,$my_path); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -