Jump to content
Sign in to follow this  
BrainPill

PHPMailer gives an error message

Recommended Posts

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.

 

 

Share this post


Link to post
Share on other sites

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 by BrainPill

Share this post


Link to post
Share on other sites

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

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...