stream_socket_enable_crypto(): Peer certificate

Viewed 784

I am trying to connect private email with my Laravel project.

.env configuration below

MAIL_DRIVER=smtp
MAIL_HOST=mail.privateemail.com
MAIL_PORT=587
MAIL_USERNAME=contact@myDomainName.com
MAIL_PASSWORD=myPrivateEmailPassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=contact@myDomainName.com
MAIL_FROM_NAME=MyCustomName

After this , I run this three command,

php artisan config:clear
php artisan config:cache
php artisan queue:restart

I have too many EmailJob files to send emails. That's why I used the last command.

What I am getting the error?

{"status":500,"data":"stream_socket_enable_crypto(): Peer certificate CN=`111-11-11-227.cprapid.com' did not match expected CN=`mail.privateemail.com'"}

Note: 111-11-11-227 is the fake number I gave here. Because I need to keep it private.

Laravel 5.8

1 Answers

You're getting the error because you are asking it to connect to a server called mail.privateemail.com, but you are actually connecting to a server called 111-11-11-227.cprapid.com. TLS is specifically designed to reject connections when certificate names don't match, protecting you from servers that are pretending to be something they are not.

There are several likely explanations for this.

  1. You have the wrong name for the mail server, and you're being redirected to the right name, but it results in a name mismatch
  2. Your server name is correct, but your hosting provider is redirecting traffic to their own mail server as a spambot prevention tactic
  3. Some bad actor is intercepting your traffic and redirecting it to their own mail server (in which case, TLS is doing its job) in the hope of tricking you into revealing credentials

If it's 1, simply change your config to use at the correct server. If its 2, perhaps point directly at your hosting provider's mail server – their docs should tell you what to do. If it's 3, count yourself lucky that we have TLS to protect our traffic and report it to your provider!

Related