0

I am currently working on cygwin. I was trying to send and email through phpmailer using my gmail account and the following script (obtained online, then hacked):

 <?php  
 require 'phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer(true); 
    try {
        $mail->ISSMTP();
        $mail->Host='smtp.gmail.com';
        $mail->SMTPDebug = 1;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "tls";
        $mail->SMTPOptions = array(
          'ssl' => array(
            'verify_peer' => true,
            'verify_peer_name' => false,
            'allow_self_signed' => true
          )
        );
        $mail->Port = 587;
        $mail->Username = "myemail@gmail.com";
        $mail->Password = "MyGooglePassword";
        $mail->setFrom('myemail@gmail.com', 'my name1');
        $mail->addAddress('anotheremail@email.fr', 'my name2');
        $mail->Subject = 'PHPMailer Exceptions test';
        $mail->Body = "Hi, This is the HTML BODY "; //HTML Body
        $mail->AltBody = 'This is a plain-text message body';
        $mail->send();
        echo "Message sent!"; 
    } catch (phpmailerException $e) {
        echo $e->errorMessage(); //Pretty error messages from PHPMailer 
    } catch (Exception $e) {
        echo $e->getMessage(); 
    }

I have seen multiple solutions on stack overflow, but I haven't found any telling how to properly self sign my localhost so that I would be able to avoid this error message:

PHP Warning:  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /usr/share/pear/phpmailer/class.smtp.php on line 346
2015-11-30 08:47:15     SMTP Error: Could not connect to SMTP host.
2015-11-30 08:47:15     CLIENT -> SERVER: QUIT
2015-11-30 08:47:15     SMTP ERROR: QUIT command failed

I have also tried resolving the issues by setting 'verify_peer' to false at "$mail->SMTPOptions" (as recommended in: PHPMailer - SSL3_GET_SERVER_CERTIFICATE:certificate verify failed), but when I do that, my gmail account refuse to cooperate saying that the signing attempt does not meet modern security standard!!

Please let me know if there is a proper tutorial that would allow me to properly set my ssl and have the email successfuly sent with the proper verifications. Here is below a link to the gmail message: Gmail - sign in attempt prevented

Community
  • 1
  • 1
  • Gmail's certs should not fail verification. It may be that your root certs are out of date and need [updating](http://curl.haxx.se/docs/caextract.html). – Synchro Nov 30 '15 at 09:34
  • @Synchro. I attached a picture of the gmail sign in attempt prevented. Also thank you for the link provided. I checked it and from it I could certify that I had the latest cacert.pem. I assigned its location in my php.ini to the variable: "curl.cainfo". Shall I have added it somewhere else as well? – Kin Rachid KONE KITO Nov 30 '15 at 10:44
  • Ah. I thought you were seeing that in the SMTP response. That just means you need to either enable less secure apps or implement xoauth2, as per the docs. – Synchro Nov 30 '15 at 18:15
  • @Syncro I tried enabling xoauth2 using the following link: https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 the only thing is that as I was running a script directly on the CLI, I used "other" (which provided me an oauthClientId and an oauthClientSecret) instead of "web application", but I got the same error message. To the above code, I added 4 new variables: $mail->AuthType, $mail->oauthUserEmail, $mail->oauthClientId and $mail->oauthClientSecret. Did I forget something? Or is it possible that the error was caused by something else? – Kin Rachid KONE KITO Dec 01 '15 at 00:52
  • You need to look at the SMTP transcript (`SMTPDebug = 2`) and see what it says. It may be that you need to log in via the web as the google message says as they may have blocked your account temporarily. – Synchro Dec 01 '15 at 07:55
  • Debugs does not provide much information. But tanks to our conversation, I was able to send an email through my yahoo account to my gmail, so I think I will be good for now. It was not absolutely necessary that I send through gmail. I just wanted to understand why it failed. And thanks to you I think I did. I will be closing this as resolved. Thanks a lot for your help in this Synchro. – Kin Rachid KONE KITO Dec 01 '15 at 14:11

0 Answers0