Support the ongoing development of Laravel.io →
Laravel Mail Configuration

Hello, I am trying to config my contact form to send email using google smtp but no email received.

The .env is like below: MAIL_DRIVER=mail

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=xyz@gmail.com

MAIL_PASSWORD=xyz

MAIL_ENCRYPTION=tls

the code at controller is like:

try {

        Mail::send('email.newEmail', $data, function ($message){

            $message->to('myemail@yahoo.com', 'myEmail')

                ->subject('New email from your website');

            $message->from('xyz@gmail.com ', 'xyz');

        });

        return view('contact-us', ['msg' => 'Email was sent successfully! We will contact you as soon as possible.', 'msgSuccess' => true]);

    }catch (Exception $ex) {

        return view('contact-us', ['msg' => 'Email failed to send, please try again later !', 'msgSuccess' => false]);

    }

and it shows that email was sent successfully but no email archive at my inbox(or spam).

I have try to change host and the email is ok(and when i try from localhost it's ok).

I am hosting my site on VPS(contabo, operating system: Ubuntu 16.04)

Can someone help me?

Thank you

Last updated 2 years ago.
0

Hello andixhafa!

If email is sent properly and working on localhost, probably you have problems with google settings.

Check these settings in your gmail account:

  1. 2step verification is enabled?
  2. in your gmail, sometimes there will come message that someone connected and was rejected, so u need to allow that

I hope that problem is there and will be solved soon :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

andixhafa andixhafa Joined 2 Sep 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.