[英]Send base64 encoded email using CodeIgniter
我正在嘗試使用CodeIgniter發送base64編碼的電子郵件。 代碼下方:
$message = base64_encode($body);
$config = Array('protocol' => 'smtp', 'smtp_host' => $smtp, 'smtp_port' => $port, 'smtp_user' => $user, 'smtp_pass' => $pass, 'mailtype' => 'html', 'charset' => 'utf-8','_bit_depths' => array('7bit', '8bit', 'base64'),'_encoding' => 'base64',);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($disemail, $disname);
$this->email->reply_to($disemail, $disname);
$this->email->to($email);
$this->email->subject($subject);
$this->email->message($message);
但是電子郵件發送不正確。 代替base64解碼,我只是在郵件中發現了base64編碼的文本。
這是發送的調試:
Mime版本:1.0
內容類型:多部分/替代; boundary =“ B_ALT_5596ca8577c5c”這是MIME格式的多部分消息。 您的電子郵件應用程序可能不支持此格式。
--B_ALT_5596ca8577c5c內容類型:文本/純文本; charset = utf-8 Content-Transfer-Encoding:base64
PGh0bWw + PGJvZHk + PGgxPnRoaXMgaXMgaHRtbDwvaDE + PC9ib2R5PjwvaHRtbD4 =
--B_ALT_5596ca8577c5c內容類型:text / html; charset = utf-8 Content-Transfer-Encoding:引用可打印
PGh0bWw + PGJvZHk + PGgxPnRoaXMgaXMgaHRtbDwvaDE + PC9ib2R5PjwvaHRtbD4 = 3D
--B_ALT_5596ca8577c5c--
我找不到確切的問題。 我正在使用CodeIgniter 2.1.3
版本。
您必須將內容的標頭設置為Content-Transfer-Encoding:base64
。 默認情況下,CodeIgniter不會設置此設置。 為此,您必須修改他們的電子郵件庫,或者簡單地擴展他們的電子郵件類並添加此標頭,以符合標准並確保不破壞核心。
CodeIgniter版本2.1.3
對於base64
編碼的電子郵件沒有任何選項。 在核心文件中編輯后,找到了解決方案。 我已經分享了解決方案。
注意:這是對核心文件的入侵。 如果只需要base64編碼的消息,請嘗試。 否則,請創建其他庫文件。
我們需要在庫文件email.php中進行一些編輯。 位於“ libraries / Email.php”中。
1 /
首先添加base64
作為編碼選項。
編輯: $_bit_depths
變量。
var $_bit_depths = array('7bit', '8bit','base64');
2 /
然后在發送控制器。 在電子郵件配置中添加'_encoding' => 'base64'
。 檢查我的代碼有問題。
請執行步驟1和2。然后執行以下步驟:
3 /
在Email.php文件中,找到function _build_message()
。
在此函數中,找到switch ($this->_get_content_type())
並轉到switch ($this->_get_content_type())
case 'html '
並刪除或注釋兩個位置。 下面的編輯代碼:
case 'html' :
if ($this->send_multipart === FALSE)
{
$hdr .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$hdr .= "Content-Transfer-Encoding: quoted-printable";
}
else
{
$hdr .= "Content-Type: multipart/alternative; boundary=\"" . $this->_alt_boundary . "\"" . $this->newline . $this->newline;
$body .= $this->_get_mime_message() . $this->newline . $this->newline;
$body .= "--" . $this->_alt_boundary . $this->newline;
// change this to text/plain to text/html
$body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$body .= "Content-Transfer-Encoding: " . $this->_get_encoding() . $this->newline . $this->newline;
// I have commented 3 lines
/*
$body .= $this->_get_alt_message() . $this->newline . $this->newline . "--" . $this->_alt_boundary . $this->newline;
$body .= "Content-Type: text/html; charset=" . $this->charset . $this->newline;
$body .= "Content-Transfer-Encoding: quoted-printable" . $this->newline . $this->newline;
*/
}
//Instead of this commented line, use line below.
//$this->_finalbody = $body . $this->_prep_quoted_printable($this->_body) . $this->newline . $this->newline;
$this->_finalbody = $body . $this->_body . $this->newline . $this->newline;
就是這樣。 現在,base64編碼的電子郵件將正確發送。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.