Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stream_socket_enable_crypto(): Peer certificate CN=`cs723.mojohost.com' did not match expected CN=`smtp.sendgrid.net'

Tags:

php

email

We are attempting to send an autoresponder email to new members. We're using the same configuration on other sites on the same server with no issue. Upon sending the email the following error is returned:

stream_socket_enable_crypto(): Peer certificate CN=cs723.mojohost.com did not match expected CN=smtp.sendgrid.net

https://gyazo.com/ffb0cb7645d51ed21ecc863f1e3196b2

We're using Laravel with connecting to: smtp.sendgrid.net port - 587 encription using TLS

We have tried the following with no success:

  • port options 25 & 2525 (returns a different error https://gyazo.com/3d42107c6aa66acc2fbe582b3a6a352e)
  • reconfigured Laravel to send AUTH command before MAIL FROM command (returns same different error 250)

Additionally we are unable to connect via PUTTY. We verified the SSH permissions are correct with MojoHost.

I've read in a different post that

The correct fix for this is to replace the invalid, misconfigured or self-signed certificate with a good one.

Attempted that with no success either. Hoping someone can provide some helpful insight. Going on a week now of trying to solve this....

Thanks, Mike

like image 935
JOAT_H1 Avatar asked Jan 09 '17 17:01

JOAT_H1


1 Answers

In the method createSmtpDriver from

\vendor\laravel\framework\src\Illuminate\Mail\TransportManager.php

it fetches the key stream from

\config\mail.php

that is later used as custom options for the stream_context_create method inside

\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php.

So to set the keys verify_peer, verify_peer_name, and allow_self_signed to solve the error mentioned by the OP you can add the following to the \config\mail.php:

'stream' => [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true,
    ],
],
like image 152
Chaibi Alaa Avatar answered Sep 19 '22 05:09

Chaibi Alaa