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条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助