带附件的PHP邮件,附件文件有noname

时间:2016-08-26 09:26:52

标签: php email pdf phpmailer

我使用发送pdf文件附件邮件我的邮件工作正常,pdf正确附加但pdf文件名显示 noname 所以如何添加正确的文件名?我的代码如下:

<?php
 $to  = $_POST['email'] . ', '; // note the comma
// subject
$subject = "service ".$_POST['TxId']." at people™";
serv_inv_list($user->uid,$_POST['TxId'],"true"); // my pdf function
$pdf_file_path = "sites/default/files/service_invoice/".$_POST['TxId'].".pdf";
chmod($pdf_file_path, 0777);
$file_name = $pdf_file_path;
$handle = fopen($file_name, "rb");
$content = fread($handle, filesize($file_name));
fclose($handle);
$encoded_content = chunk_split(base64_encode($content));
$message = ' msg is comming';

$boundary = "public_Service"; 
//header
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "From:priyank@gmail.com"."\r\n"; 
$headers .= "Reply-To: brijesh@gmail.com" . "\r\n";
$headers  .= "Content-Type: multipart/mixed; ";
$headers  .= "boundary=".$boundary."\r\n";
// $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 

//plain text 
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
$body .= chunk_split(base64_encode($message)); 

//attachment
$body .= "--$boundary\r\n";
$body .="Content-Type: mime_content_type($filename) name=\"$fname\"\r\n";
$body .="Content-Disposition: attachment; filename=\"$filename\"\r\n";
$body .="Content-Transfer-Encoding: base64\r\n";
$body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
$body .= $encoded_content; 

如何解决我的问题?

0 个答案:

没有答案