dqluw20882 2014-04-02 06:02
浏览 32
已采纳

PHPMailer:include(/var/www/sendingmail/protected/extensions/phpmailer/JPhpMailer.php)无法打开流没有这样的文件或目录

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;
  • 写回答

2条回答 默认 最新

  • dongyongyu0789 2014-04-02 08:18
    关注

    I have figured it by myself,

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

    Its working now

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?