Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"stream_socket_enable_crypto(): Peer certificate CN=`gains.nanosupercloud.com' did not match expected CN=`smtp.sendgrid.net'" in shared hosting

Tags:

php

email

laravel

I'm working in mail in laravel. I've following configuration.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=********
MAIL_PASSWORD=########
MAIL_ENCRYPTION=tls

I've already tried this one but not working

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

And many more similar question but still i don't get the solution. I've following error:

ErrorException (E_WARNING) stream_socket_enable_crypto(): Peer certificate CN=gains.nanosupercloud.com' did not match expected CN=smtp.sendgrid.net'

I don't know what i'm doing wrong. Here is the code used for email sending.

public function toMail($notifiable)
{
    return (new MailMessage)
                ->from(\Config::get('values.app_email'),\Config::get('values.app_name'))
                ->subject('Successfully approved your Company')
                ->greeting(sprintf('Hello %s', $this->user->name))
                ->line('Your company has been approved successfully. Now, it will be visible to our website');
}

Any kind of suggestions are appreciated.

Note: Everything works perfectly in local server(ubantu 16.04)

like image 489
Sagar Gautam Avatar asked Dec 13 '25 08:12

Sagar Gautam


2 Answers

The answer i am giving may look funny but i have same error while sending mail in the live server

just change this

MAIL_DRIVER=smtp

to

MAIL_DRIVER=sendmail

I don't know the reason How the hell is this working but it works fine for me

like image 139
ManojKiran Appathurai Avatar answered Dec 15 '25 22:12

ManojKiran Appathurai


add this line in .env file to disable mail encryption

MAIL_ENCRYPTION = NULL
like image 27
fatemeh sadeghi Avatar answered Dec 15 '25 21:12

fatemeh sadeghi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!