简体   繁体   English

带有 AJAX 的 PHPMailer 不发送附件

[英]PHPMailer With AJAX Does Not Send Attachments

I'm using PHPMailer on a simple contact form, and to submit that form I'm using jQuery AJAX.我在一个简单的联系表单上使用 PHPMailer,并使用 jQuery AJAX 提交该表单。 The contact form works as expected along with AJAX, and now that everything is working I'm tackling this issue.联系表单与 AJAX 一起按预期工作,现在一切正常,我正在解决这个问题。

File attachments aren't included in the email sent by PHPMailer when submitting the form via AJAX.通过 AJAX 提交表单时,PHPMailer 发送的电子邮件中不包含文件附件。

How can I also send attachments when submitting the form with jQuery AJAX?使用 jQuery AJAX 提交表单时如何发送附件?

You need to set headers of mail.您需要设置邮件标题。 Some of header examples are below:-一些标题示例如下:-

$header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n";
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM