这是我在控制器中的代码
public function actionSendemail()
{
$model = new EmailForm();
if(isset($_POST['EmailForm']))
{
$model->attributes=$_POST['EmailForm'];
if($model->validate()){
$body = $_POST['User']['firstname'].$_POST['User']['lastname'].
$_POST['User']['$contactno'].$_POST['User']['body'];
$message = new YiiMailMessage;
$params = array('myMail'=>$body);
$message->subject = $_POST['User']['subject'];
$message->setBody($params, 'text/html');
$message->addTo('test@gmail.com');
$message->from = $_POST['User']['email'];
Yii::app()->mail->send($message);
}
}
$list = TblPage::model()->findByPk(6);
$this->render('contactview', array('list'=>$list, 'model'=>$model));
}
但显示错误:
include(YiiMailMessage.php)[function.include]:无法打开流:没有这样的文件或目录
如何发送电子邮件?
答案 0 :(得分:0)
如果您已下载并包含在extension / yii-mail / YiiMail中,则可将其放入您的应用程序配置中。
'mail' => array(
'class' => 'ext.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions' => array(
'host' => 'smtp.gmail.com',
'username' => 'XXXX@gmail.com',
'password' => 'XXXX',
'port' => '465',
'encryption'=>'tls',
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),