使用PHP mail()发送附带附件的HTML电子邮件

时间:2017-01-09 19:47:02

标签: php email phpmailer html-email email-attachments

我正在尝试使用邮件发送带有PDF附件的HTML电子邮件,但我收到此错误:

  

警告:mail():找到多个或格式错误的换行符   第69行的文件名中的additional_header

是否可以通过这种方式发送附件:

$file = "New CV - small.pdf";
$file_size = filesize($file);
$filename = "My CV";
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);

$uid = md5(uniqid(time()));

$content = chunk_split(base64_encode($content));

$email = format_email ($name, $company['name'], $ending, false, $link);

$headers = "From: Paul Ledger <route1designs@hotmail.co.uk>\r\n";
$headers .= "Reply-To: route1designs@hotmail.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= $subject."\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";
$headers .= "--".$uid."--";


mail($email_to, $subject, $email, $headers);

0 个答案:

没有答案
相关问题