能够通过PhpMailer发送邮件吗?

时间:2015-06-25 10:55:20

标签: php email phpmailer

我已在我的项目中配置和安装composer,我还需要将autoload.php文件放入我的文件中以发送mail.my所有登录详细信息也正确但在运行应用程序时我获取SMTP ERROR: Password command failed i在下面列出了详细的错误。请帮我解决这个问题

            <?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';
            }
            ?>

运行此文件时出错:

          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

2 个答案:

答案 0 :(得分:0)

使用function your_function() { global $user; $username = $user->name; // Instead of $_SESSION['name'] // ... your query } openssl扩展名时应启用

在php.ini文件中,从此行$m->SMTPSecure = 'ssl';删除分号(如果可用)

你可以试试&#39; ts&#39;对于SMTPSecure

;extension=php_openssl.dll

使用此设置检查希望它会有所帮助

答案 1 :(得分:0)

尝试使用“tls”表示SMTPSecure,使用587表示端口。

此外,如果您已经在php.ini文件中删除了分号,就像kevikeks建议的那样,它仍然不起作用。

试试这个: 确保您的详细信息正确为$ m-&gt;用户名和$ m-&gt;密码。 然后在设置/ security / lesssecureapps下转到您的Google帐户,并为不太安全的应用启用访问权限。现在运行.php文件,看看你是否收到了电子邮件。

如果有帮助,请告诉我。