Hello,
I'm trying to send mails from the local with gmail SMTP but it is impossible.
I use XAMPP for mac, PHP 5.6.3, Apache 2.4.10, OpenSSL 1.0.1j (is enabled in php.ini) and CodeIgniter.
i have this in the function
$mail = new PHPMailer();
$mail->IsSMTP(); // establecemos que utilizaremos SMTP
$mail->SMTPDebug = 4;
$mail->Debugoutput = 'html';
$mail->SMTPAuth = true; // habilitamos la autenticaci贸n SMTP
$mail->SMTPSecure = "tls"; // establecemos el prefijo del protocolo seguro de comunicaci贸n con el servidor
$mail->Host = "smtp.gmail.com"; // establecemos GMail como nuestro servidor SMTP
$mail->Port = 587; // establecemos el puerto SMTP en el servidor de GMail
$mail->Username = "[email protected]"; // la cuenta de correo GMail
$mail->Password = "*********"; // password de la cuenta GMail
And I have this error:
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
----------------------------------------------------------------------------------
A PHP Error was encountered
Severity: Warning
Message: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Filename: PHPMailer/class.smtp.php
Line Number: 344
---------------------------------------------------------------------------------
SMTP Error: Could not connect to SMTP host.
I searched a lot but i can't find the solution anywhere.
Thanks.
This is covered in the troubleshooting guide. Your server is using an invalid or self-signed certificate and you're running PHP 5.6. The proper solution is to fix your server rather than disabling certificate checks.
Thanks, i fixed it adding this code:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
OK, but do understand that this "fix" is to make your connection insecure.
Yes i know but is only for a project in the university, not for a real application. Thanks
Hi Synchro, could you suggest a way to fix my server settings. As I'm using the troubleshooting work around at present.
@10029759 figure out why you need the workaround - e.g. Whether you very has expired, is self-signed or whatever, and fix it. Then PHPMailer will be able to work properly.
getting such error , using laragon as a local server.
please help me!
2018-02-01 18:22:58 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2018-02-01 18:22:58 Connection: opened
2018-02-01 18:22:59 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y18sm198595pfa.175 - gsmtp
2018-02-01 18:22:59 CLIENT -> SERVER: EHLO localhost
2018-02-01 18:22:59 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [103.226.90.197]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-02-01 18:22:59 CLIENT -> SERVER: STARTTLS
2018-02-01 18:22:59 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-02-01 18:22:59 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 [C:\laragon\www\gmail\vendor\phpmailer\phpmailer\src\SMTP.php line 404]
SMTP Error: Could not connect to SMTP host.
2018-02-01 18:22:59 CLIENT -> SERVER: QUIT
2018-02-01 18:23:00
2018-02-01 18:23:00
2018-02-01 18:23:00 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
If you can't click one link or read the rest of this thread, I'm not sure that anything I type here will help.
djmakaay, If you're sending mails from local environment, smtp4dev should solve your problem
Most helpful comment
Thanks, i fixed it adding this code:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);