Unable to send email to gmail accounts in Laravel

221 Views Asked by At

I am trying to integrate email([email protected]) into my Laravel application. I am not using Mailtrap or Google's SMTP. My hosting provider has an email server. I am planning to use that email server. The problem is that when I send an email from [email protected] to [email protected] is working. But when sending mail from [email protected] to [email protected] I didn't get any mail.

.env file

MAIL_MAILER=smtp
MAIL_HOST=mail.domail.com
MAIL_PORT="465"
MAIL_USERNAME="[email protected]"
MAIL_PASSWORD="password"
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

app/http/controller/EmailController.php

Mail::to('[email protected]')->send(new GetStartedMail($request));

app/mail/GetStartedMail.php

public function build()
    {
        return $this->from('[email protected]', 'No Reply')
            ->subject('New message from '.$this->request->get('name',''))
            ->to('[email protected]', $this->request->get('name',''))
            ->markdown('emails.get-started');
    }

when i edit those files EmailController.php & GetStartedMail.php of [email protected] to [email protected]. I got email from [email protected]

When i mail from outlook ([email protected]) to gmail ([email protected]) is working**

Can anyone help me understand why I am facing this issue?

1

There are 1 best solutions below

2
Snapey On

In order to have google accept your email, you must have an SPF record in your DNS that says your hosting provider is allowed to send email on behalf of the domain.

There are plenty of guides on the internet about SPF records. I picked this one.

https://support.google.com/a/answer/10685031

You could have an existing SPF record that says ONLY your main mail provider is allowed to send on your behalf.