我正在尝试从网站向邮件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 SMTPUTF8 2017-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登录平台XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-12 -03 12:03:48客户 - >服务器:AUTH LOGIN 2017-12-03 12:03:48服务器 - >客户:334 VXNlcm5hbWU6 2017-12-03 12:03:48客户 - >服务器:bWlsaW5kYmh1dmFkMTk4OEBnbWFpbC5jb20 = 2017-12-03 12:03:48服务器 - >客户:334 UGFzc3dvcmQ6 2017-12-03 12:03:48客户 - >服务器:bW5iQDI4MDc = 2017-12-03 12:03:49服务器 - >客户: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错误:密码命令失败: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 connect()失败。无法发送https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息.Mailer错误:SMTP connect()失败。 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
}
?>
答案 0 :(得分:0)
删除$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
或链接到您要发送的实际附件。同时更新php.ini
中的证书也适用于我。