Reputation:
I am trying to send feedback to mail id from web site but I am getting this error:
2017-12-03 12:03:48 Could not access file: /var/tmp/file.tar.gz 2017-12-03 12:03:48 Could not access file: /tmp/image.jpg 2017-12-03 12:03:48 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:48 CLIENT -> SERVER: EHLO www.shreephotovision.ml 2017-12-03 12:03:48 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [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 CLIENT -> SERVER: STARTTLS 2017-12-03 12:03:48 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2017-12-03 12:03:48 CLIENT -> SERVER: EHLO www.shreephotovision.ml 2017-12-03 12:03:48 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [185.27.134.45] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-12-03 12:03:48 CLIENT -> SERVER: AUTH LOGIN 2017-12-03 12:03:48 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2017-12-03 12:03:48 CLIENT -> SERVER: bWlsaW5kYmh1dmFkMTk4OEBnbWFpbC5jb20= 2017-12-03 12:03:48 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2017-12-03 12:03:48 CLIENT -> SERVER: bW5iQDI4MDc= 2017-12-03 12:03:49 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:49 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:49 SMTP Error: Could not authenticate. 2017-12-03 12:03:49 CLIENT -> SERVER: QUIT 2017-12-03 12:03:49 SERVER -> CLIENT: 221 2.0.0 closing connection p42sm12855091wrb.28 - gsmtp 2017-12-03 12:03:49 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Here is my code:
<?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 = '[email protected]'; // 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('[email protected]', '');
$mail->addAddress('[email protected]', ''); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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
}
?>
Upvotes: 0
Views: 2930
Reputation: 3
Remove $mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
or link to an actual attachment you want to send. Also updating the certificates in the php.ini
worked for me.
Upvotes: 0