1

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="support@getalow.com"
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.

Code Flow
  • 209
  • 3
  • 15
  • are you using a queue to send emails? Check your .env's QUEUE_CONNECTION and also try to clear the config cache. – Anuj Shrestha Jun 08 '22 at 07:20
  • No I am not using queue, and I also clear cache, optimize clear – Code Flow Jun 09 '22 at 00:20
  • if there was an error in mail sending and you aren't using queue then your user register request should have given you the 500 error, not controller success. My best guess is your mail server/ mail config has some issue or you haven't initiated code to send email – Anuj Shrestha Jun 09 '22 at 08:17

1 Answers1

1

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.
JS TECH
  • 1,556
  • 2
  • 11
  • 27