环境:Claws Mail 3.9.1, PHP 5.4.16, PHPMailer 5.2.6 c5e9f7873f 现象:PHPMailer 发送带附件的邮件,直接使用 AddAttachment() 方法 $mailer-AddAttachment$attach_file; 没有其他设置。Claws Mail 收到信以后,查看邮件内容为空白, 附件栏显示: messag
环境:Claws Mail 3.9.1, PHP 5.4.16, PHPMailer 5.2.6 c5e9f7873f
现象:PHPMailer 发送带附件的邮件,直接使用 AddAttachment() 方法
$mailer->AddAttachment($attach_file);
没有其他设置。Claws Mail 收到信以后,查看邮件内容为空白, 附件栏显示:
message/rfc822 multipart/mixed
以下就是空白了。 而能够正常识别附件的邮件,附件栏内容一般为:
message/rfc822 multipart/mixed text/plain text/html (这个是附件的 mime 类型)
gmail 和 mutt 中识别这样的邮件是正常的。
分析:通过对比正常和不正常的邮件原始码, 发现不正常邮件在声明内容是分节之后,多了一句传输编码声明,比如:
Content-Type: multipart/mixed; boundary="b1_95a848b14cb4385965320b915d5829dd" Content-Transfer-Encoding: base64
最后的 Content-Transfer-Encoding 就是比正常邮件多的一行。
由于邮件原始码的这个部分,只是用来声明后续邮件是多个部分组成, 并定义了每个部分的辨识边界 boundary,并没有实际的内容, 所以应当是不需要声明编码类型的。在 PHPMailer 中相关代码为:
public function GetMailMIME() { $result = ''; switch($this->message_type) { case 'inline': $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1].'"'); break; case 'attach': case 'inline_attach': case 'alt_attach': case 'alt_inline_attach': $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1].'"'); break; case 'alt': case 'alt_inline': $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1].'"'); break; default: // Catches case 'plain': and case '': $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); break; } //RFC1341 part 5 says 7bit is assumed if not specified if ($this->Encoding != '7bit') { $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); }
特意加上了这个申明,因为按照 RFC1341,7bit 编码类型是默认的。
解决: 或许问题是出在 Claws Mail 上,但我暂时只能修改 PHPMailer 来适应这个问题了。 上面的问题弄清楚之后,在 multipart 后面不添加传输编码声明即可:
//RFC1341 part 5 says 7bit is assumed if not specified // Not after multipart/mixed, claws-mail will not recoginize attachment if (($this->Encoding != '7bit') && (!in_array($this->message_type, array( 'attach', 'inline_attach', 'alt_attach', 'alt_inline_attach', )))) { $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); }
原文地址:Claws Mail 不识别 PHPMailer 发送的附件, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment