【发布时间】:2018-05-17 00:43:04
【问题描述】:
我正在尝试从网站向邮件 ID 发送反馈,但我收到此错误:
2017-12-03 12:03:48 无法访问文件:/var/tmp/file.tar.gz 2017-12-03 12:03:48 无法访问文件:/tmp/image.jpg 2017 -12-03 12:03:48 服务器-> 客户端:220 smtp.gmail.com ESMTP p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:48 客户端-> 服务器:EHLO www.shreephotovision.ml 2017-12 -03 12:03:48 服务器-> 客户端:250-smtp.gmail.com 为您服务,[185.27.134.45] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTP 250 UTF8 -12-03 12:03:48 客户端 -> 服务器:STARTTLS 2017-12-03 12:03:48 服务器 -> 客户端:220 2.0.0 准备启动 TLS 2017-12-03 12:03:48 客户端 - > 服务器:EHLO www.shreephotovision.ml 2017-12-03 12:03:48 服务器 -> 客户端:250-smtp.gmail.com 随时为您服务,[185.27.134.45] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-流水线 250-CHUNKING 250 SMTPUTF8 2017-12-03 12:03:48 客户端-> 服务器:身份验证登录 2017-12-03 12:03:48版本->客户端:334 VXNlcm5hbWU6 2017-12-03 12:03:48 客户端->服务器:bWlsaW5kYmh1dmFkMTk4OEBnbWFpbC5jb20= 2017-12-03 12:03:48 服务器->客户端:3324 UGFzc3dvcmQ12-0336 48 CLIENT -> SERVER: bW5iQDI4MDc= 2017-12-03 12:03:49 SERVER -> CLIENT: 534-5.7.14 请通过 Web 浏览器和 534-5.7.14 登录,然后重试。 534-5.7.14 了解更多信息,请访问 534 5.7.14 https://support.google.com/mail/answer/78754 p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:49 SMTP 错误:密码命令失败:534-5.7.14 请通过您的网络浏览器登录,然后534-5.7.14 然后再试一次。 534-5.7.14 了解更多信息,请访问 534 5.7.14 https://support.google.com/mail/answer/78754 p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:49 SMTP 错误:无法验证。 2017-12-03 12:03:49 客户端-> 服务器:退出 2017-12-03 12:03:49 服务器-> 客户端:221 2.0.0 关闭连接 p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03 :49 SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 无法发送邮件。邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
这是我的代码:
<?php
$name = $_REQUEST['name'] ;
$mobile = $_REQUEST['mobile'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'milindbhuvad1988@gmail.com'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('milindbhuvad1988@gmail.com', '');
$mail->addAddress('milindbhuvad1988@gmail.com', ''); // Add a recipient
$mail->addAddress('milindbhuvad1988@gmail.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'You have received feedback from your website!';
$mail->Body = "
<strong>Name:</strong> $name <hr>
<strong>Name:</strong> $mobile <hr>
<strong>Email:</strong> $email <hr>
<strong>Message:</strong> $message <hr>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
?>
<script type="text/javascript">
alert('Thanks Your Feedback');
window.location.href='index.html';
</script>';
<?php
}
?>
【问题讨论】:
-
鉴于错误
Password command failed和Could not authenticate,您自己的猜测是什么? -
同样,您认为
Could not access file: /var/tmp/file.tar.gz可能意味着什么? -
实际上有 2 个错误。您的文件无法附加,并且您缺少 GMail-oAuth 凭据。