<?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);