这是我的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如果有人能帮我解决这个问题,我将不胜感激!
发布于 2017-07-10 21:53:43
我建议使用SwiftMailer使用一种不同的方法。
您可以轻松地使用json文件获取该组件,并查看其效果。http://swiftmailer.org/docs/introduction.html#basic-usage
https://stackoverflow.com/questions/45011804
复制相似问题