[英]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.