Code Flow
Code Flow

Reputation: 229

Laravel 9 Symfony mailer not working - mail sent from app but not received in gmail

In Laravel 8 I was able to send an email verification email. And now in Laravel 9 email sent message appears but I don't receive an email.

I have used my correct mail host provided by domain with port, username, and password as previously and checked enough times. I have also changed ssl to tls but no success.

.env file

MAIL_MAILER=smtp
MAIL_HOST=mail.getalow.com
MAIL_PORT=465
MAIL_USERNAME=********
MAIL_PASSWORD=*********
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

I also added 'verify_peer' => false in mail.php config file but no success.

mail.php

'smtp' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'timeout' => null,
    'verify_peer' => false,   // <------ IT HAS TO BE HERE
],

my User.php model also has implements MustVerifyEmail as I do everytime.

class User extends Authenticatable implements MustVerifyEmail

In registration controller event(new Registered($user)); is presented

RegistrationController.php

// Register a new user
public function register(RegistrationRequest $request) {
    $user = User::create($request->validated())->assignRole(['User', 'Commenter']);;
    event(new Registered($user));
    Auth::login($user);

    return to_route('home')
    ->with(Helpers::Toast(
        'Welcome ' . $user->name,
        'Your account has been created.',
        'success',
        '5000'
    ));
}

I tried it from localhost to mailtrap it works. But when I upload it to server with all details of server in env file as above. I receive success message as in registration controller, but I don't receive activation email on my registered email.

I am using shared hosting, cpanel as hosting provider

What am I missing please help. I stucked on it for 4 days.

Upvotes: 1

Views: 2632

Answers (1)

JS TECH
JS TECH

Reputation: 1583

You said you are using cPanel shared hosting server.

There is no problem in your Laravel 9 code. The problem is on your DNS setting of your email in cPanel. You have to change CNAME, MX, TXT records on cPanel as provided by your hosting provider.

For example:

If you are using ohodomain hosting provider.

  1. Go to account settings.
  2. Select your domain from list of your domains.
  3. Go to Manage Email.
  4. There you will see the error with its solution that you have to solve.
  5. Add the provided CNAME, MX, TXT records on your cPanel's Zone Editor.

Upvotes: 1

Related Questions