0

I have been getting an error while i try to send an email using laravel 5.5 with gmail.

MAIL_DRIVER=smtp
MAIL_HOST=gmail-smtp-msa.l.google.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

I changed the mail host from smtp.google.com to that one becuase i could not reach smtp.google.com

Here is the error i get when i try to send mail

stream_socket_enable_crypto(): Peer certificate CN=`smtp.gmail.com' did not match expected CN=`gmail-smtp-msa.l.google.com'

And this is the error that i use when i use mail_host smtp.google.com

Connection could not be established with host smtp.google.com 
[php_network_getaddresses: getaddrinfo failed: Name or service not known #0

Note that everything was working well with my testing server mailtrap. So how can i make this work for production?

Willie Mwewa
  • 341
  • 3
  • 13

2 Answers2

5

you have error in mail host MAIL_HOST=smtp.gmail.com

As per your question you have used MAIL_HOST=gmail-smtp-msa.l.google.com and MAIL_HOST=gmail-smtp-msa.l.google.com

But gmail host is smtp.gmail.com

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
4

Usually setting encryption to ssl works:

'encryption' => 'ssl'

On your config/mail.php:

But you better try to stick with smtp.gmail.com:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygmailadress
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • ssl is less secure then tls and it seems turned off for gmail, I could not connect using ssl but it worked just fine using tls – niko craft Jun 25 '18 at 20:56