Yii,无法加载PHPMailer
几天来,我一直在尝试使用gmail从本地服务器发送电子邮件。。我曾经用一个yii扩展来实现它,但过了一段时间,它不起作用了,我尝试添加整个phpMail,并以正确的方式进行邮寄 这是我的代码:Yii,无法加载PHPMailer,php,email,yii,phpmailer,Php,Email,Yii,Phpmailer,几天来,我一直在尝试使用gmail从本地服务器发送电子邮件。。我曾经用一个yii扩展来实现它,但过了一段时间,它不起作用了,我尝试添加整个phpMail,并以正确的方式进行邮寄 这是我的代码: static function gmail($email) { $mail = new phpmailer(); $mail->IsSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = true
static function gmail($email)
{
$mail = new phpmailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->Username = "mail@gmail.com";
$mail->Password = "password"; //best to keep this in your config file
$mail->Subject = 'subject';
$mail->Body = 'message';
$mail->addAddress($email);
$mail->send();
}
我从中下载了PHPMailer库,并将所有组件提取到文件夹中。
我添加到配置文件的方式如下:
'import'=>array(
'application.models.*',
'application.components.*',
'application.components.PHPMailer.*'
),
$mail = new YiiMailer();
//$mail->clearLayout();//if layout is already set in config
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "account@gmail.com";
$mail->Password = "password";
$mail->setFrom('no-reply@strandedgrounds.sr', 'Stranded Grounds');
$mail->setSubject('Recuperacion de contraseña');
$mail->AddAddress("mail@hotmail.com");
$mail->send();
在第一次尝试时,我遇到以下错误include(phpmailer.php):无法打开流:没有这样的文件或目录
更新:我忘了说,我访问这个函数的方式是这样的
Mailer::gmail(“$this->email”)
其中Mailer.php具有gmail功能。仔细检查您的php.ini文件,确保phpmailer位于include\u路径中,因为除了基于您提供的代码之外,所有内容看起来都不错
(很抱歉,我会将此添加到评论中,但我现在还无法发表评论。)我不太确定,我正在使用YIS phpmailer扩展几个月,它一直工作得很好 但是,请尝试使用Github:
require_once <PATH TO PHPMAILER> . 'class.phpmailer.php';
$mail = new PHPMailer();
[...] Rest of your code here
require_一次。”class.phpmailer.php';
$mail=new PHPMailer();
[…]此处是您的其余代码
替换为你的
class.phpmailer.php的absulute路径
我可以通过检查gmail历史安全性来发送邮件,这表明有人试图以无效授权访问我的帐户,最后我使用了YiiMailer,这让gmail有点混乱
代码是这样的:
'import'=>array(
'application.models.*',
'application.components.*',
'application.components.PHPMailer.*'
),
$mail = new YiiMailer();
//$mail->clearLayout();//if layout is already set in config
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "account@gmail.com";
$mail->Password = "password";
$mail->setFrom('no-reply@strandedgrounds.sr', 'Stranded Grounds');
$mail->setSubject('Recuperacion de contraseña');
$mail->AddAddress("mail@hotmail.com");
$mail->send();
注意你的情况。通过查看Github,该类被命名为
PHPMailer
而不是PHPMailer
。此外,我不确定Phpmailer是否与Yii一起开箱工作。但是现在有一个方便的扩展。@chris--我已经尝试了PHPMailer
,但仍然没有找到该类。我也尝试过这个扩展,它没有给我错误,但它不发送邮件。我已经安装并运行了stunnel,以防万一,看看你的报价-我认为你编辑的行应该是Mailer::gmail($this->email)代码>。单引号不会导致它传入实例。您还忽略了任何可能的错误-我建议您至少执行return$mail->send()代码>@Synchro如果我不能得到类错误,我可以做这样的建议。我尝试了PHPMailer
附带的其他扩展,并添加了它们的调试,其中大多数没有显示错误,有些只是提供错误验证,关于引号,这就是一个例子。我做这件事的真实方式是这样的Mailer::gmail('nosthertus@hotmail.com');如果要使用smtp身份验证发送电子邮件,则不需要code>php.ini。或者我就是这么想的think@nosthertus-哦,好吧,我只是根据你得到的include错误来做的。此外,正如Chris在上面提到的……我相信我正在使用他引用的phpmailer(这对我来说一直很有效)。