使用 PHPmailer 发送邮件时遇到问题

问题描述 投票:0回答:0
<?php
use PHPMailer\PHPMailer\PHPMailer;

require_once 'vendor/autoload.php';

$mail = new PHPMailer;


$mail->SMTPDebug = 3;

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = 'YOUR_URL_HERE';
$mail->Password = 'mypass';

// set email content
$mail->setFrom('YOUR_URL_HERE', 'Sender Name');
$mail->addAddress('YOUR_URL_HERE', 'Recipient Name');
$mail->Subject = 'Test email from PHPMailer';
$mail->Body = 'This is a test email sent from PHPMailer using Gmail SMTP';

// send email
if (!$mail->send()) {
    echo 'Error: ' . $mail->ErrorInfo;
} else {
    echo 'Email sent successfully';
}
?>

调试输出:

2023-04-22 10:44:48 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2023-04-22 10:44:49 Connection: opened
2023-04-22 10:44:50 SMTP INBOUND: "220 smtp.gmail.com ESMTP k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp"
2023-04-22 10:44:50 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp
2023-04-22 10:44:50 CLIENT -> SERVER: EHLO localhost
2023-04-22 10:44:50 SMTP INBOUND: "250-smtp.gmail.com at your service, [213.255.128.166]"
2023-04-22 10:44:50 SMTP INBOUND: "250-SIZE 35882577"
2023-04-22 10:44:50 SMTP INBOUND: "250-8BITMIME"
2023-04-22 10:44:50 SMTP INBOUND: "250-STARTTLS"
2023-04-22 10:44:50 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2023-04-22 10:44:50 SMTP INBOUND: "250-PIPELINING"
2023-04-22 10:44:50 SMTP INBOUND: "250-CHUNKING"
2023-04-22 10:44:50 SMTP INBOUND: "250 SMTPUTF8"
2023-04-22 10:44:50 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [213.255.128.166]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2023-04-22 10:44:50 CLIENT -> SERVER: STARTTLS
2023-04-22 10:44:50 SMTP INBOUND: "220 2.0.0 Ready to start TLS"
2023-04-22 10:44:50 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2023-04-22 10:44:55 CLIENT -> SERVER: EHLO localhost
2023-04-22 10:44:55 SMTP INBOUND: "250-smtp.gmail.com at your service, [213.255.128.166]"
2023-04-22 10:44:55 SMTP INBOUND: "250-SIZE 35882577"
2023-04-22 10:44:55 SMTP INBOUND: "250-8BITMIME"
2023-04-22 10:44:55 SMTP INBOUND: "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
2023-04-22 10:44:55 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2023-04-22 10:44:55 SMTP INBOUND: "250-PIPELINING"
2023-04-22 10:44:55 SMTP INBOUND: "250-CHUNKING"
2023-04-22 10:44:55 SMTP INBOUND: "250 SMTPUTF8"
2023-04-22 10:44:55 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [213.255.128.166]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2023-04-22 10:44:55 Auth method requested: UNSPECIFIED
2023-04-22 10:44:55 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
2023-04-22 10:44:55 Requested auth method not available:
2023-04-22 10:44:55 Auth method selected: LOGIN
2023-04-22 10:44:55 CLIENT -> SERVER: AUTH LOGIN
2023-04-22 10:44:55 SMTP INBOUND: "334 VXNlcm5hbWU6"
2023-04-22 10:44:55 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2023-04-22 10:44:55 CLIENT -> SERVER: xxx
2023-04-22 10:44:55 SMTP INBOUND: "334 UGFzc3dvcmQ6"
2023-04-22 10:44:55 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2023-04-22 10:44:55 CLIENT -> SERVER: xxx
2023-04-22 10:44:55 SMTP INBOUND: "535-5.7.8 Username and Password not accepted. Learn more at"
2023-04-22 10:44:55 SMTP INBOUND: "535 5.7.8 https://support.google.com/mail/?p=BadCredentials k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp"
2023-04-22 10:44:55 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp
2023-04-22 10:44:55 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/?p=BadCredentials k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp
SMTP Error: Could not authenticate.
2023-04-22 10:44:55 CLIENT -> SERVER: QUIT
2023-04-22 10:44:55 SMTP INBOUND: "221 2.0.0 closing connection k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp"
2023-04-22 10:44:55 SERVER -> CLIENT: 221 2.0.0 closing connection k18-20020a05600c0b5200b003edf2dc7ca3sm6991959wmr.34 - gsmtp
2023-04-22 10:44:55 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Error sending email: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
xampp smtp gmail phpmailer
© www.soinside.com 2019 - 2024. All rights reserved.