环境: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 发送的附件, 感谢原作者分享。

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器