首先下載:
http://www.yiiframework.com/extension/phpmailer/files/phpmailer-alpha2.zip
或者進這個地址也行:http://pan.baidu.com/share/link?shareid=405509&uk=4077977192
下載後解壓,得到phpmailer文件夾,將它放入項目文件夾\protected\extensions\下面
- Yii::import('application.extensions.phpmailer.JPhpMailer');
- $mail = new JPhpMailer();
- $mail->IsSMTP();
- $mail->Host = 'smtp.163.com';//郵件服務器
- $mail->SMTPAuth = true;
- $mail->Username = '[email protected]';//這裏寫發送方的賬戶名
- $mail->Password = '123456';//發送方的賬戶密碼
- $mail->SetFrom('[email protected]', 'admin');//顯示在郵件的發送方信息
- $mail->Subject = 'title';//這裏是標題
- //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
- $mail->MsgHTML('郵件的正文');
- $mail->AddAddress('收件方的郵箱地址', 'John Doe');
- $mail->Send();
這樣就能發送郵件了。但是經過試驗,QQ郵箱是沒問題的,163的郵箱在有中文的情況下會顯示亂碼。
就需要更改這個文件了:項目文件夾\protected\extensions\phpmailer\class.phpmailer.php中的
第59行改爲:
- public $CharSet = 'utf-8';
第72行改爲:
- public $Encoding = 'base64';
這樣就大功告成了。