我想用PHPmailer发送附件,但是当我添加' addattachment'字符串,邮件以纯文本形式发送。这是我的代码:
$headers .= "AddAttachment('downloads/file.pdf','file.pdf')\n";
$headers .= "Reply-To: Contoso <noreply@contoso.com>\n";
$headers .= "From: Contoso <info@contoso.com>\n";
$headers .= "Organization: Contoso \n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=UTF-8\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-Mailer: PHP". phpversion() ."\n" ;
mail($to, $subject, $body, $headers,$param);
所以脚本没有&#39; AddAttachment&#39;规则。如何成功添加附件?
答案 0 :(得分:0)
以下是如何发送附件的教程。
http://webcheatsheet.com/php/send_email_text_html_attachment.php#attachment
仅仅设置标题是不够的。您必须将附件作为base64编码添加到您的邮件中。
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
也许使用lib更容易做一些像PHPMailer或Swift Mailer我喜欢的工作。
Content-Type: application/zip; name="attachment.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment