BrainPill Posted January 5, 2018 Share Posted January 5, 2018 I downloaded a piece of software from github but I can not really get it working, so I would like to get some tips of people who have used this. The name of the script is PHPMailer. I have the latest version. I decided to use gmail for smtp. with autentication. In the troubleshooting they recommended to use composer, but I dont get what / why they want it. What is composer used for? As far as i get it is used to run php commands from a command line. This my script: <?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'; require 'A:\wamp64\www\PHPMailer\src\Exception.php'; require 'A:\wamp64\www\PHPMailer\src\PHPMailer.php'; require 'A:\wamp64\www\PHPMailer\src\SMTP.php'; $mail = new PHPMailer(true); // Passing `true` enables exceptions try { //Server settings $mail->SMTPDebug = 4; // 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 = 'my.own.gmail@gmail.com'; // SMTP username $mail->Password = '12345fake'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('my.own.gmail@gmail.com', 'My Own Gmail'); $mail->addAddress('recipient.person999@gmail.com', 'John Doe'); // Add a recipient // $mail->addAddress('ellen@example.com'); // Name is optional // $mail->addReplyTo('info@example.com', 'Information'); // $mail->addCC('cc@example.com'); // $mail->addBCC('bcc@example.com'); //Attachments // $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments // $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'To John Doe (test mail) '; $mail->Body = 'This is the HTML message body <b>in bold!</b>'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } ?> when running the script I dont receive an email and I get the following output with a message: 2018-01-05 13:21:25 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 [A:\wamp64\www\PHPMailer\src\SMTP.php line 404] SMTP Error: Could not connect to SMTP host. 2018-01-05 13:21:25 CLIENT -> SERVER: QUIT see the complete output here: Quote 2018-01-05 13:21:25 Connection: opening to smtp.gmail.com:587, timeout=300, options=array() 2018-01-05 13:21:25 Connection: opened 2018-01-05 13:21:25 SMTP INBOUND: "220 smtp.gmail.com ESMTP o15sm3865380edk.25 - gsmtp" 2018-01-05 13:21:25 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP o15sm3865380edk.25 - gsmtp 2018-01-05 13:21:25 CLIENT -> SERVER: EHLO 127.0.0.1 2018-01-05 13:21:25 SMTP INBOUND: "250-smtp.gmail.com at your service, [12.34.567.890]" 2018-01-05 13:21:25 SMTP INBOUND: "250-SIZE 35882577" 2018-01-05 13:21:25 SMTP INBOUND: "250-8BITMIME" 2018-01-05 13:21:25 SMTP INBOUND: "250-STARTTLS" 2018-01-05 13:21:25 SMTP INBOUND: "250-ENHANCEDSTATUSCODES" 2018-01-05 13:21:25 SMTP INBOUND: "250-PIPELINING" 2018-01-05 13:21:25 SMTP INBOUND: "250-CHUNKING" 2018-01-05 13:21:25 SMTP INBOUND: "250 SMTPUTF8" 2018-01-05 13:21:25 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [12.34.567.890]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8 2018-01-05 13:21:25 CLIENT -> SERVER: STARTTLS 2018-01-05 13:21:25 SMTP INBOUND: "220 2.0.0 Ready to start TLS" 2018-01-05 13:21:25 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2018-01-05 13:21:25 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 [A:\wamp64\www\PHPMailer\src\SMTP.php line 404] SMTP Error: Could not connect to SMTP host. 2018-01-05 13:21:25 CLIENT -> SERVER: QUIT 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 2018-01-05 13:21:25 Connection: closed SMTP Error: Could not connect to SMTP host. Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host. I'm curious what causes this error and would like to solve it. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 5, 2018 Share Posted January 5, 2018 It might be an SSL problem on your server, a workaround is described here: https://github.com/PHPMailer/PHPMailer/issues/1022 1 Link to comment Share on other sites More sharing options...
BrainPill Posted January 25, 2018 Author Share Posted January 25, 2018 (edited) not sure if this is for my host. I have phpmailer + composer installed under WAMP (windows 10) I checked if I had verify_peer in scripts in the phpmailer directory but nothing was found. I installed the latest version of phpmailer (version 6.0.2) I'm desperate and dont know how to solve this. Edited January 25, 2018 by BrainPill Link to comment Share on other sites More sharing options...
BrainPill Posted January 25, 2018 Author Share Posted January 25, 2018 I found my error. I solved it by adding the following piece of code $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); I first tried to improve the old install (which suddenly stopped working some time ago) and then searched in the scripts for verify_peer and found it in the old install. I now realize I can just add it to the script that I initially posted in this thread. Thanks for helping me out Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now