0
votes

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 = '[email protected]';           
    $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('[email protected]', '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.

1
Have you tried port = 587 instead of 465? And have you tried SMTPSecure = 'TLS' instead of 'SSL'? What does your debug output show? You may need to change SMTPDebug = 3 to get more details. - Mr Glass
chagne to $mail->SMTPSecure = 'tls'; and make sure Two Steps Authentication is turned off - Abdulla Nilam
The problem was most likely that your original server had outdated CA certificates. This exact problem and multiple solutions to it are in the guide the error message links to. - Synchro

1 Answers

0
votes

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, ), );
 }