1,首先,去官网把邮件类down下来,网址http://www.yiiframework.com/extension/mailer/#download
2,解压,把mailer文件夹放在extensions文件夹下,extensions可以自己建立,与config,modules等同级,
3,在控制器中应用,一句$mail = Yii::createComponent('application.extensions.mailer.EMailer');,调用过来,打印$mail,出错则检查路径。
4,mailer下phpmailer里面有readme,里面有例子。
$mail = Yii::createComponent('application.extensions.mailer.EMailer');
$mail->Host = 'smtp.sina.com';
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.sina.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "你邮箱的用户名"; // SMTP username
$mail->Password = "你邮箱的密码"; // SMTP password
$mail->From = "guanyang_zgler@sina.com";
$mail->FromName = "guanliyang";
$mail->AddAddress("1145828184@qq.com", "收件人"); // name is optional
$mail->Subject = "发送标题";
$mail->Body = "这里是我给你发送的内容!";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
var_dump($mail->Send());
此方法放win下好用,放linux下可能不能用,需要改两个地方。
1,把 @fsockopen 改成 @pfsockopen,改函数名。
2,$this->Mailer = ‘smtp’;改成$this->Mailer = ‘SMTP’;改大写。