程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP基礎知識 >> ZEND FRAMEWORK SMTP發送郵件的亂碼問題

ZEND FRAMEWORK SMTP發送郵件的亂碼問題

編輯:PHP基礎知識
 

<?php

 

require_once ROOT_PATH . '/Zend/Mail.php';
require_once ROOT_PATH . '/Zend/Mail/Transport/Smtp.php';
$mail = new Zend_Mail("UTF-8");//設置郵件編碼
$config = array('auth'=>'login',
'username'=>"kylingood",//電子件用戶名
'password'=>"這裡是填寫你電子郵件密碼",
'ssl'=>"ssl"//服務器SSL選項
);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
$mail->setDefaultTransport($transport);
$mailcontent='郵件內容';

$mail->setBodyHtml($mailcontent);//可以發送HTML的郵件.真方便!
$mail->setFrom('[email protected]', 'kylingood');
$mail->addTo($email, 'kylingood');
$title=$thisArray ['username'].',用戶您好,這是網站激活驗證郵件!';
$mail->setSubject("=?UTF-8?B?".base64_encode($title)."?=");
$mail->send();
?>

以上代碼雖然解決了標題中的亂碼,但是並沒有解決郵件內容中的亂碼,最後程序改為如下,在126的郵箱及yahoo的郵箱中均得到正常輸出。

//發送郵件
$mail = new Zend_Mail("gbk");
//$host = $this->_request->getHttpHost();
//$basedir = $this->_request->getBasePath();
 

$url = 'www.126.com'; //鏈接地址
$subject = 'silver帳戶激活';

$content = $to . '您好!<br /></br />這裡是由silver發送的用戶帳號激活郵件,點擊以下鏈接完成激活操作。<br /><a target="_blank" href="'. $url .'" target="_blank">'. $url .'</a><br /><br />silver<br />'. date('Y-m-d');
//$content = "=?UTF-8?B?".base64_encode($content)."?=";
$config = array('auth'=> 'login', 'name'=> 'smtp.sina.com', 'port'=> 25, 'username'=> '[email protected]', 'password'=> '******');
$transport = new Zend_Mail_Transport_Smtp('smtp.sina.com', $config);
$pos = strpos($to, '@');
$toname = substr($to, 0, $pos);
$mail->addTo($to, $toname);
$mail->setFrom('[email protected]', 'silver');
$mail->setSubject($subject);
$mail->setBodyHtml($content);
$mail->send($transport);
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved