i'm trying to send a mail. i want to use Gmail server to send, for now i just want it to send to the same account from its being sent.
i'm using YiiMailer extension because it seems to be easy to use, this is the action i have in my controller:
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-Type: text/plain; charset=UTF-8";
// mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
$mail = new YiiMailer('contact', array(
'message'=>$model->body,
'name'=>$model->name,
'description'=>'Contact form'
));
$mail->setFrom($model->email, $model->name);
$mail->setSubject($model->subject);
$mail->setTo(Yii::app()->params['adminEmail']);
$mail->isSMTP();
$mail->host = "smtp.gmail.com";
$mail->port = 465;
$mail->Username = "username@gmail.com";
$mail->Password = "password";
if($mail->send())
{
Yii::app()->user->setFlash('contact','Gracias por contactarnos, te responderemos tan pronto como podamos.');
$this->refresh();
}
else
{
Yii::app()->user->setFlash('error','Error enviando correo.');
$this->refresh();
}
}
}
$this->render('contact',array('model'=>$model));
}
the adminMail is the same like account@gmail.com
i dont't know if i have the right settings for gmail, i'm sure the condition of the function doesn't exist so it does nothing.
just to make sure. this is my config:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'ext.YiiMailer.YiiMailer'
),
PD: i found the gmail settings around post. i'm not sure if they changed the settings.