无法使用SMTP通过PHP发送电子邮件

时间:2017-07-10 12:16:58

标签: php email xampp smtp

这是我的email.php文件:

 <?php

    $to = "someemail@gmail.com";
    $from = "myemail@gmail.com";

    $subject="Email";
      $body="hi";  
    $headers = array(
        'From' => $from,
        'To' =>  $to,
        'Subject' => $subject
        );

             $smtp = Mail::factory('smtp', array(
                    'host' => 'ssl://smtp.gmail.com',
                    'port' => '465',
                    'auth' => true,
                    'username' => 'myemail@gmail.com',
                    'password' => 'password'
                ));
            $mail = $smtp->send( $to, $headers, $body);

            if (PEAR::isError($mail)) {
                echo('<p>' . $mail->getMessage() . '</p>');
            } else {
                echo('<p>Message successfully sent!</p>');
            }

?>      

我已启用对安全性较低的应用,DisplayUnlockCaptcha以及IMAP的访问权限。我没有在帐户中启用两步验证。但是,我仍然会收到以下错误。

authentication failure [SMTP: Invalid response code received from server (code: 534, response: 5.7.14 Please log in via your web browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14 https://support.google.com/mail/answer/78754 i28sm32905934pfk.17 - gsmtp)]

我在Windows中使用XAMPP,这是我在php.ini文件中添加的内容:

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 465
; For Win32 only.
sendmail_from = myemail@gmail.com

如果有人可以帮我解决这个问题,我将非常感激!

1 个答案:

答案 0 :(得分:0)

我建议使用SwiftMailer采用不同的方法。

您可以轻松地使用json文件获取组件,并查看其结果。 http://swiftmailer.org/docs/introduction.html#basic-usage

相关问题