PHPMailer SMTP错误:无法使用gmail作为smtp服务器进行身份验证 [英] PHPMailer SMTP Error: Could not authenticate using gmail as smtp server

查看:852
本文介绍了PHPMailer SMTP错误:无法使用gmail作为smtp服务器进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过 appfog
i上托管的应用程序发送电子邮件,使用以下可正常工作的代码在本地主机上,但在appfog上失败。
JPhpMailer extend class.PhpMailer.php

  $ mailer = new JPhpMailer(true); 
$ mailer-> IsSMTP();
$ mailer-> Mailer =smtp;
// $ mailer-> SMTPSecure =='tls';
$ mailer-> Host ='ssl://smtp.gmail.com';
$ mailer-> Port ='465';
$ mailer-> SMTPAuth = true;
// $邮件程序 - > SMTPSecure = true;
$ mailer->使用者名称='me@gmail.com';
$ mailer->密码='zzzzzzz';
$ mailer-> SetFrom($ to ['from'],$ to ['from_name']);
$ mailer-> AddAddress($ to ['to'],$ to ['to_name']);
$ mailer-> Subject = $ to ['subject'];
$ mailer-> Body = $ to ['body'];
$ mailer->发送();

这里是phpMailer中执行失败的行`if($ tls){
if(!$ this-> smtp-> StartTLS()){
抛出新的phpmailerException($ this-> Lang('tls'));


$ $ p $ //我们必须在谈判后重新发送HELO
$ this-> smtp-> ; HELLO(你好$);
}

$ connection = true;
if($ this-> SMTPAuth){
if(!$ this-> smtp->身份验证($ this->用户名,$ this->密码)){
**强壮的文本抛出新的phpmailerException($ this-> Lang('authenticate')); **}
}
}
$ index ++;
if(!$ connection){
throw new phpmailerException($ this-> Lang('connect_host'));


解决方案

下面的代码适用于我:

  require(phpmailer / class.phpmailer.php); 

$ mail = new PHPMailer();

$ mail-> IsSMTP(); //设置邮件使用SMTP
$ mail-> SMTPAuth = true; //打开SMTP认证
$ mail-> SMTPSecure =tls;
$ mail-> Host =smtp.gmail.com; //指定主服务器和备份服务器
$ mail->端口= 587;
$ mail->用户名=myemail@gmail.com; // SMTP用户名
$ mail->密码=mypass; // SMTP密码

$ mail-> From =myemail@gmail.com;
$ mail-> FromName =myname;
$ mail-> AddAddress(myaddress@gmail.com,myname);

$ mail-> WordWrap = 50; //设置自动换行为50个字符
$ mail-> IsHTML(true); //将电子邮件格式设置为HTML

$ mail-> Subject =这是主题;
$ mail-> Body =这是HTML邮件正文< b>加粗!< / b>;
$ mail-> AltBody =这是非HTML邮件客户端的纯文本正文;

if(!$ mail-> Send())
{
echo无法发送消息。< p>;
回显邮件错误:。 $ MAIL-> ERRORINFO;
出口;
}

echo消息已发送;


I am failing to send email in my application hosted on appfog i am using the following code which works fine on localhost but fail on appfog. JPhpMailer extend class.PhpMailer.php

                    $mailer = new JPhpMailer(true);
                    $mailer->IsSMTP();
                    $mailer->Mailer = "smtp";
                    //$mailer->SMTPSecure == 'tls'; 
                    $mailer->Host = 'ssl://smtp.gmail.com';
                    $mailer->Port = '465';
                    $mailer->SMTPAuth = true;
                    //$mailer->SMTPSecure = true; 
                    $mailer->Username = 'me@gmail.com';
                    $mailer->Password = 'zzzzzzz';
                    $mailer->SetFrom($to['from'], $to['from_name']); 
                    $mailer->AddAddress($to['to'],$to['to_name'] ); 
                    $mailer->Subject = $to['subject'];
                    $mailer->Body = $to['body'];
                    $mailer->Send();

here is the line that in phpMailer that fails to execute`if ($tls) { if (!$this->smtp->StartTLS()) { throw new phpmailerException($this->Lang('tls')); }

         //We must resend HELO after tls negotiation
        $this->smtp->Hello($hello);
      }

       $connection = true;
      if ($this->SMTPAuth) {
         if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
         **strong text throw new phpmailerException($this->Lang('authenticate')); **            }
      }
     }
   $index++;
    if (!$connection) {
       throw new phpmailerException($this->Lang('connect_host'));
     }

解决方案

The code below is working for me :

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";  // specify main and backup server
$mail->Port = 587;
$mail->Username = "myemail@gmail.com";  // SMTP username
$mail->Password = "mypass"; // SMTP password

$mail->From = "myemail@gmail.com";
$mail->FromName = "myname";
$mail->AddAddress("myaddress@gmail.com", "myname");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";

这篇关于PHPMailer SMTP错误:无法使用gmail作为smtp服务器进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆