Phpmailer error: Could not authenticate - php

I know there's a lot a similar questions, I've read them all, tried everything in the comments. Still doesn't work.
I've created the gmail account for this project and set the less secure aplication usage configurations from the beginning.
If anyone can give me any ideas I've aprecciate it a lot, I've been trying to solve this for months.
This is the output:
" 2018-06-03 21:03:33 SERVER -> CLIENT:
2018-06-03 21:03:33 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
Message hasnt been sent. Mailer Error: SMTP Error: Could not authenticate.> "
And this is my send.php code:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
require 'vendor/autoload.php';
if(isset($_REQUEST['send']))
{
$name= $_REQUEST['name'];
$tel= $_REQUEST['tel'];
$email= $_REQUEST['email'];
$preference= $_REQUEST['preference'];
$area= $_REQUEST['area'];
$message= $_REQUEST['message'];
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'mygmailaccount#gmail.com';
$mail->Password = 'thepassword';
$mail->SMTPSecure = 'TSL';
$mail->Port = 587;
$mail->CharSet= 'UTF-8';
// Port 465 for SSL auth. Also tried 587 for authenticated TLS
$mail->setFrom($email, $name);
$mail->addAddress('mygmail#gmail.com', 'Myname');
$mail->isHTML(true);
$mail->Subject = "Contact from ".$name;
$mail->Body = "Name:". $name. ". </br> Tel:". $tel. ". </br> Email:". $email. ". </br> Preference:". $preference. ". </br> Area:". $area. ". </br> Message:". $message. ". </br> ";
$mail->AltBody = "Name:". $name. ". ::: Tel:". $tel. ". ::: Email:". $email. ". ::: Preference:". $preference. ". ::: Area:". $area. ". ::: Message:". $message. ". ::: ";
$mail->send();
$_SESSION["success"] = "Thanks for the message";
}
catch (Exception $e)
{
echo 'Message hasnt been sent. Mailer Error: ', $mail->ErrorInfo;
}
}
Edit: I've tried what Abdulla and Glass said, deactivated the 2 step verification and changed to tsl with port 587 and debug 3 and get this output:
2018-06-03 22:03:55 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2018-06-03 22:03:55 Connection: opened
2018-06-03 22:03:55 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP u74-v6sm3867212qku.55 - gsmtp
2018-06-03 22:03:55 CLIENT -> SERVER: EHLO localhost
2018-06-03 22:03:55 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [190.2.100.71]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2018-06-03 22:03:55 CLIENT -> SERVER: STARTTLS
2018-06-03 22:03:56 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-06-03 22:03:56 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [H:\xampp\htdocs\mati\PHPMailer\src\SMTP.php line 406]
SMTP Error: Could not connect to SMTP host.
2018-06-03 22:03:56 CLIENT -> SERVER: QUIT
2018-06-03 22:03:56 SERVER -> CLIENT:
2018-06-03 22:03:56 SMTP ERROR: QUIT command failed:
2018-06-03 22:03:56 Connection: closed
SMTP Error: Could not connect to SMTP host.
El mensaje no ha sido enviado. Mailer Error: SMTP Error: Could not connect to SMTP host.
Edit2: It is solved, I've uploaded in a provisional server that use tsl authentication and worked perfectly. I can thank you enough #abdulla-nilam and #mr-glass for your contribution.
It finnaly sent the message so, thank you again. It didn't worked at first from my localhost but in the provissional server works just fine.

I think you should try this:
$mail = new \PHPMailer(true);
$mail->CharSet = 'UTF-8'; $mail->isHTML();
$mail->Host = ...//my config
$mail->Port = ...//my port $mail->isSMTP();
if (version_compare(PHP_VERSION, '5.6.0') >= 0){
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ), );
}

Related

PHPmailer won't use SMTP

I am using PHPMailer 6.2 (shared webhosting so I grabbed the latest version of the code from Github and uploaded it to my FTP. When I want to send mail without SMTP, there are no problems sending mail. When I do use SMTP (and I do need to), however, nothing happens. It kind of looks like the page won't load at all. I don't get errors or notices, so I'm at a loss what I'm doing wrong here. Using an SMTP test tool, I see that my credentials and the connection details are OK. Here's my code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require __DIR__.'/PHPMailer/src/Exception.php';
require __DIR__.'/PHPMailer/src/PHPMailer.php';
require __DIR__.'/PHPMailer/src/SMTP.php';
$mail = new PHPMailer(TRUE);
try {
$mail->setFrom("xxx", "Test");
$mail->addAddress('xxx', 'Test');
$mail->Subject = 'Bericht via de website';
$mail->Body = "hier een testbericht";
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = 'tls';
$mail->Username = 'xxx';
$mail->Password = 'xxx';
$mail->Port = 587;
$mail->send();
} catch (Exception $e) {
echo $e->errorMessage();
} catch (\Exception $e) {
echo $e->getMessage();
}
die("done");
?>
Edit: after 20 minutes of loading, the following response is generated:
2020-11-28 19:40:07 CLIENT -> SERVER: EHLO <my/e-mail rcpt domain>
2020-11-28 19:45:07 SERVER -> CLIENT:
2020-11-28 19:45:07 SMTP ERROR: EHLO command failed:
2020-11-28 19:45:07 CLIENT -> SERVER: HELO <my/e-mail rcpt domain>
2020-11-28 19:50:07 SERVER -> CLIENT:
2020-11-28 19:50:07 SMTP ERROR: HELO command failed:
2020-11-28 19:50:07 CLIENT -> SERVER: STARTTLS
2020-11-28 19:55:07 SERVER -> CLIENT:
2020-11-28 19:55:07 SMTP ERROR: STARTTLS command failed:
SMTP Error: Could not connect to SMTP host.
2020-11-28 19:55:07 CLIENT -> SERVER: QUIT
2020-11-28 20:00:07 SERVER -> CLIENT:
2020-11-28 20:00:07 SMTP ERROR: QUIT command failed:
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.```

Facing errors while sending mail in local server

I am unable to send an email on my local server.
I used following phpmailer code to test mail sending:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 587; // SMTP port
$mail->Username = ""; // username
$mail->Password = ""; // password
$mail->SetFrom('', 'Test');
$mail->Subject = "I hope this works!";
$mail->MsgHTML('Blah');
$address = "";
$mail->AddAddress($address, "Test");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But I get the following error:
2020-07-06 09:20:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y7sm6517117pjy.54 - gsmtp
2020-07-06 09:20:08 CLIENT -> SERVER: EHLO localhost
2020-07-06 09:20:08 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [157.49.67.14]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-07-06 09:20:08 CLIENT -> SERVER: STARTTLS
2020-07-06 09:20:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2020-07-06 09:20:09 CLIENT -> SERVER: QUIT
2020-07-06 09:20:09
2020-07-06 09:20:09
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Please suggest possible solutions.

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

2018-03-05 18:25:08 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP
o5sm27821483pfh.51 - gsmtp 2018-03-05 18:25:08 CLIENT -> SERVER: EHLO
localhost 2018-03-05 18:25:08 SERVER -> CLIENT: 250-smtp.gmail.com at
your service, [43.247.156.6]250-SIZE
35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8 2018-03-05 18:25:08 CLIENT -> SERVER: STARTTLS 2018-03-05
18:25:08 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS SMTP Error:
Could not connect to SMTP host. 2018-03-05 18:25:09 CLIENT -> SERVER:
QUIT 2018-03-05 18:25:09 2018-03-05 18:25:09 SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message
has been sent
my code is
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions
try {
//Server settings
$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 = 'girish8134#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
//Recipients
$mail->setFrom('girish8134#gmail.com', 'Giri');
$mail->addAddress('girish3055#gmail.com', 'giri3055'); // Add a recipient
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message bod';
$mail->AltBody = 'This is the body is';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
first try this> https://support.google.com/accounts/answer/1064203?hl=en
Disabling two step authentication.
If it doesn't work like that, you can always try and simplify some code (and try ssl - port 467):
$mail->setFrom('girish8134#gmail.com');
$mail->addAddress('girish3055#gmail.com');
Let me know if it worked.
Try this:
$mail->SMTPSecure = 'ssl'; // Use SSL encryption,
$mail->Port = 465 // change port to 465

php mailer smtp connect() failed to gmail

I have tried to send mail through gmail. I have seen other people solutions but it didn't work for me. What is the problem in my code?
Here is my output error
2017-06-27 13:53:54 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP o131sm2910537wmd.26 - gsmtp
2017-06-27 13:53:54 CLIENT -> SERVER: EHLO localhost
2017-06-27 13:53:54 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [213.55.85.206]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2017-06-27 13:53:54 CLIENT -> SERVER: STARTTLS
2017-06-27 13:53:55 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2017-06-27 13:53:55 CLIENT -> SERVER: QUIT
2017-06-27 13:53:55
2017-06-27 13:53:55
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Here is the source code
date_default_timezone_set('Etc/UTC');
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "hajiman00#gmail.com";
$mail->Password = "xxxxxxx";
$mail->setFrom('hajiman00#gmail.com', 'Support From HITD');
$mail->addAddress('hjibril37#gmail.com', 'Hassen Jibril');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("MUKERA 123");
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

PHPMailer - SMTP Error: Could not connect to SMTP host

I'm trying to send email using PHPMailer. When I tried sending the email from gmail account, it works perfectly fine. However, I would like to send the email from my own SMTP, but there seems to be an error. What could be the problem? Please help me. Thank you.
Using smtp.gmail.com :
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
Using mail.distech.com.my :
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'mail.distech.com.my';
$mail->SMTPAuth = true;
$mail->Username = 'myemail#distech.com.my';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = 'myemail#distech.com.my';
$mail->addAddress('amalina#distech.com.my');
$mail->Subject = 'Test';
$mail->Body = 'Test message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Error using mail.distech.com.my
2015-06-23 06:58:45 Connection: opening to mail.distech.com.my:587, timeout=300, options=array ( )
2015-06-23 06:58:45 Connection: opened
2015-06-23 06:58:45 SERVER -> CLIENT: 220-server.firstonline-server16.com ESMTP Exim 4.85 #2 Tue, 23 Jun 2015 14:58:45 +0800 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2015-06-23 06:58:45 CLIENT -> SERVER: EHLO 192.168.1.20
2015-06-23 06:58:46 SERVER -> CLIENT: 250-server.firstonline-server16.com Hello 192.168.1.20 [115.135.120.220] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP
2015-06-23 06:58:46 CLIENT -> SERVER: STARTTLS
2015-06-23 06:58:46 SERVER -> CLIENT: 220 TLS go ahead
Warning: stream_socket_enable_crypto() [function.stream-socket-enable-crypto]: SSL: The operation completed successfully. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 344
2015-06-23 06:58:46 SMTP Error: Could not connect to SMTP host.
2015-06-23 06:58:46 CLIENT -> SERVER: QUIT
Notice: fwrite() [function.fwrite]: send of 6 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\ehars\phpmailer\class.smtp.php on line 937
2015-06-23 06:58:46 SERVER -> CLIENT:
2015-06-23 06:58:46 SMTP ERROR: QUIT command failed:
2015-06-23 06:58:46 Connection: closed 2015-06-23 06:58:46 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
UPDATE :
Checked my phpinfo () and the ssl has been enabled.

Categories