繁体   English   中英

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

[英]Unable to Send Email Via PHP using 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

如果有人可以帮助我解决此问题,我将非常感谢!

我建议使用SwiftMailer的另一种方法。

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

暂无
暂无

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

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