国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Claws Mail不識別PHPMailer發送的附件的原因及解決辦法

2024-05-04 21:49:41
字體:
來源:轉載
供稿:網友

筆記遇到一個問題:Claws Mail不識別PHPMailer發送的附件,經過烽數次在網上找資料,終于找到原因并解決,現在把原因及解決辦法整理如下.

環境: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

以下就是空白了, 而能夠正常識別附件的郵件,附件欄內容一般為:

  1. message/rfc822 
  2.     multipart/mixed 
  3.         text/plain 
  4.         text/html   (這個是附件的 mime 類型) 

gmail 和 mutt 中識別這樣的郵件是正常的.

分析:通過對比正常和不正常的郵件原始碼,發現不正常郵件在聲明內容是分節之后,多了一句傳輸編碼聲明,比如:

  1. Content-Type: multipart/mixed; 
  2.     boundary="b1_95a848b14cb4385965320b915d5829dd" 
  3. Content-Transfer-Encoding: base64 //開源軟件:Vevb.com 

最后的 Content-Transfer-Encoding 就是比正常郵件多的一行,由于郵件原始碼的這個部分,只是用來聲明后續郵件是多個部分組成,并定義了每個部分的辨識邊界 boundary,并沒有實際的內容,所以應當是不需要聲明編碼類型的,在 PHPMailer 中相關代碼為:

  1. public function GetMailMIME() { 
  2.   $result = ''
  3.   switch($this->message_type) { 
  4.     case 'inline'
  5.       $result .= $this->HeaderLine('Content-Type''multipart/related;'); 
  6.       $result .= $this->TextLine("tboundary="" . $this->boundary[1].'"'); 
  7.       break
  8.     case 'attach'
  9.     case 'inline_attach'
  10.     case 'alt_attach'
  11.     case 'alt_inline_attach'
  12.       $result .= $this->HeaderLine('Content-Type''multipart/mixed;'); 
  13.       $result .= $this->TextLine("tboundary="" . $this->boundary[1].'"'); 
  14.       break
  15.     case 'alt'
  16.     case 'alt_inline'
  17.       $result .= $this->HeaderLine('Content-Type''multipart/alternative;'); 
  18.       $result .= $this->TextLine("tboundary="" . $this->boundary[1].'"'); 
  19.       break
  20.     default
  21.       // Catches case 'plain': and case '': 
  22.       $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 
  23.       break
  24.   } 
  25.   //RFC1341 part 5 says 7bit is assumed if not specified 
  26.   if ($this->Encoding != '7bit') { 
  27.     $result .= $this->HeaderLine('Content-Transfer-Encoding'$this->Encoding); 
  28.   } 

特意加上了這個申明,因為按照 RFC1341,7bit 編碼類型是默認的.

解決:或許問題是出在 Claws Mail 上,但我暫時只能修改 PHPMailer 來適應這個問題了,上面的問題弄清楚之后,在 multipart 后面不添加傳輸編碼聲明即可:

  1. //RFC1341 part 5 says 7bit is assumed if not specified 
  2. // Not after multipart/mixed, claws-mail will not recoginize attachment 
  3. if (($this->Encoding != '7bit') && (!in_array($this->message_type, array
  4.     'attach'
  5.     'inline_attach'
  6.     'alt_attach'
  7.     'alt_inline_attach'
  8. )))) { 
  9.   $result .= $this->HeaderLine('Content-Transfer-Encoding'$this->Encoding); 

終于解決了這個問題,現在我們可以放心的用PHPMailer發送附件了.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安化县| 仁怀市| 温宿县| 云林县| 济宁市| 聂荣县| 昆山市| 武清区| 墨竹工卡县| 兰考县| 潞城市| 富民县| 平顶山市| 吕梁市| 嵊州市| 蓝山县| 油尖旺区| 正蓝旗| 化德县| 漳州市| 永州市| 缙云县| 姜堰市| 芜湖县| 多伦县| 成安县| 泾源县| 远安县| 新竹市| 长丰县| 九龙坡区| 十堰市| 弥勒县| 曲阳县| 仙桃市| 五原县| 陆川县| 绩溪县| 涟水县| 义乌市| 吴忠市|