PHPMailer: include(/var/www/sendingmail/protected/extensions/phpmailer/JPhpMailer.php) failed to open stream No such file or directory

StackOverflow https://stackoverflow.com/questions/22802761

  •  26-06-2023
  •  | 
  •  

Frage

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;
War es hilfreich?

Lösung

I have figured it by myself,

I have included this line in my controller -:- require("class.phpmailer.php");

Its working now

Andere Tipps

Your phpmailer file should be included in the folder phpmailer which contains extensions as main folder and it contains applications as main folder

phpmailer folder should have the file phpmailer.php

applications->extensions->phpmailer->phpmailer.php is the correct path

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top