I'm using PHPMailer to send mails in Yii.
I have downloaded the extension from Github and included them in /protected/extensions
I have also imported it in main.php
.
But when I try to send mail, it gives me an error
failed to open stream: No such file or directory
My controller:
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = true;
$mail->Username = 'from@gmail.com';
$mail->Port = '465';
$mail->Password = 'password';
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 0;
$mail->SetFrom('from@gmail.com', 'myname');
$mail->Subject = 'PHPMailer Test Subject via GMail, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress('to@gmail.com', 'John Doe'); $mail->Send();
Yii::app()->user->setFlash('contact','Thank you for... as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}
There is an error with this line:
$mail = new JPhpMailer;