简体   繁体   English

可以通过PhpMailer发送邮件?

[英]enable to send mail via PhpMailer?

I have configure and install composer in my project,i also require the autoload.php file into my file to send mail.my all login details are also correct but while running the application im getting SMTP ERROR: Password command failed i have included detailed error below.please help me to sort out this problem 我已经在项目中配置并安装了composer,我也需要将autoload.php文件发送到我的文件中以发送邮件。我的所有登录详细信息也都正确,但是在运行应用程序时出现SMTP ERROR: Password command failed我包含了详细错误下面。请帮助我解决这个问题

            <?php
            require_once 'vendor/vendor/autoload.php';
            $m = new PHPMailer;

            $m->isSMTP();
            $m->SMTPAuth = true;
            $m->SMTPDebug = 2;
            $m->Host= 'smtp.gmail.com';
            $m->Username = 'suhasgawde10@gmail.com';
            $m->Password = '*************';

            $m->SMTPSecure = 'ssl';
            $m->Port = 465;

            $m->From = 'suhasgawde10@gmail.com';
            $m->FromName = 'Suhas Gawde';
            $m->addReplyTo('suhasgawde10@gmail.com','Reply address');
            $m->addAddress('suhasgawde10@gmail.com','Suhas Gawde');

            $m->Subject = "Here is the subject";
            $m->Body = 'this is mailed send throught php mailer';
            $m->AltBody= 'this is mailed send throught php mailer';

            if(!$m->send()){
                echo "Mailer Error: " . $m->ErrorInfo;
            }
            else{
                echo 'success';
            }
            ?>

Error while running this file : 运行此文件时出错:

          2015-06-25 10:48:42   SERVER -> CLIENT: 220 mx.google.com ESMTP
          si7sm29610201pbc.54 - gsmtp 2015-06-25 10:48:42   CLIENT -> 
          SERVER: EHLO localhost 2015-06-25 10:48:43    SERVER -> CLIENT: 
          250-mx.google.com at your service, [59.182.41.18] 250-SIZE 
          35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-            
          CLIENTTOKEN XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-
          CHUNKING 250 SMTPUTF8 2015-06-25 10:48:43 CLIENT -> SERVER: AUTH
          LOGIN 2015-06-25 10:48:43 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2015-
          06-25 10:48:43    CLIENT -> SERVER:     
          c3VoYXNnYXdkZTEwQGdtYWlsLmNvbQ== 2015-06-25 
          10:48:44  SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2015-06-25 10:48:44  
         CLIENT -> SERVER: Z2FuYXBhdGlAMTAwOA== 2015-06-25 10:48:44 SERVER -
          > CLIENT: 534-5.7.14 Please log in via your web browser and 534-
          5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 
          https://support.google.com/mail/answer/78754 si7sm29610201pbc.54 - 
          gsmtp 2015-06-25 10:48:44 SMTP ERROR: Password command failed: 
          534-5.7.14 Please log in via your web browser and 534-5.7.14 then 
          try again. 534-5.7.14 Learn more at 534 5.7.14
          https://support.google.com/mail/answer/78754 si7sm29610201pbc.54 - 
          gsmtp 2015-06-25 10:48:44 SMTP Error: Could not authenticate. 
          2015-06-25 10:48:44   CLIENT -> SERVER: QUIT 2015-06-25 10:48:45  
          SERVER -> CLIENT: 221 2.0.0 closing connection si7sm29610201pbc.54 
          - gsmtp 2015-06-25 10:48:45   SMTP connect() failed. 
          https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer 
          Error: SMTP connect() failed. 
          https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

While using $m->SMTPSecure = 'ssl'; 当使用$m->SMTPSecure = 'ssl'; openssl extension should be enabled openssl扩展名应启用

In php.ini file remove semicolon from this line ;extension=php_openssl.dll (if available) 在php.ini文件中,从此行删除分号;extension=php_openssl.dll (如果可用)

Or 要么

you can try 'tls' for SMTPSecure 您可以为SMTPSecure尝试使用“ tls”

$m->SMTPSecure = 'tls';
$m->Host = 'smtp.gmail.com';
$m->Port = 587;

Check with this setting hope it will help 检查此设置,希望它会有所帮助

Try using "tls" for SMTPSecure and 587 for Port. 尝试将“ tls”用于SMTPSecure,将587用于端口。

Also if you already remove the semicolon from the file in php.ini like kevikeks suggested, and it still does not work. 另外,如果您已经像kevikeks建议的那样从php.ini中的文件中删除了分号,它仍然不起作用。

Try this: Make sure your details are correct for $m->Username and $m->Password. 尝试以下操作:确保$ m-> Username和$ m-> Password的正确信息。 Then go to your google account under setting/security/lesssecureapps and turn on access for less secure apps. 然后转到设置/安全性/ lesssecureapps下的Google帐户,然后为安全性较低的应用程序打开访问权限。 Now run the .php file and see if you get an email. 现在运行.php文件,看看是否收到电子邮件。

Let me know if this helps. 让我知道是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM