Yii学习笔记【6】

使用YiiMailMessage发送邮件:

安装yii-mail到protected/extension下

配置protected/config/main.php,如下
'import' => array(
......
'application.extensions.yii-mail.*',
),

......
'components' => array(
'mail' => array(
'class' => 'application.extensions.yii-mail.YiiMail',
'transportType' => 'smtp', /// case sensitive!
'transportOptions' => array(
'host' => 'mail.syncomni.com',
'username' => '[email protected]',
// or [email protected]
'password' => 'Sitbwp4m2w',
// 'port' => '465',
// 'encryption' => 'ssl',
),
// 'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
),
发送邮件
// 发送电子邮件
$message = new YiiMailMessage;
$message->setSubject($model->notice_subject);
$message->setBody($model->notice);
$message->setTo('[email protected]');
$message->from = Yii::app()->params['adminEmail'];
Yii::app()->mail->send($message);

你可能感兴趣的:(学习笔记)