Search code examples
laravelemail-verification

Laravel 5.7 not sending verify emails


after successful registration my app doesn't send verification email (It only sends to emails on my domain) and I'm redirected to /email/verify as if it was sent (checked spam and promotion folders). On other hand my forget password system works like a charm so I guess my .env is good.
Here are my routes for auth and verification:

Route::group([
    'prefix'=>'{locale}',
    'where'=>['locale'=>'[a-zA-Z]{2}'],
    'middleware'=>'setlocale',
],function(){
Route::get('/login','Auth\LoginController@showLoginForm')->name('login')->middleware('guest');
Route::post('/login','Auth\LoginController@login')->middleware('guest');
Route::post('/logout','Auth\LoginController@logout')->name('logout');
Route::get('register','Auth\RegisterController@showRegistrationForm')->name('register')->middleware('guest');
Route::post('register','Auth\RegisterController@register');
Route::get('/email/verify', 'Auth\VerificationController@show')->name('verification.notice');
}); //closed group locale
    Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
    Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');

When I receive email on my own domain email address it works.

RegisterController.php

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
    public function redirectTo(){
        return route('verification.notice',app()->getLocale());
    }
}

Solution

  • Hosting company gave me new different MAIL_HOST it works now, maybe old one was blacklisted or something. Thanks everyone for comments.