Search code examples
laravelemailregistration

email has been set but Cannot send message without a sender address Laravel


i want to send an email welcoming users when they register. so in the registration controller after validation, i have my code to send email. everything set properly still couldnt send email. here is my code.

 protected function create(array $data): User
    {
//
        $email = request()->get('email');
        Mail::to($email)->send(new NewUserWelcomeMail());

        return User::create([

            
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'username' => $data['username'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
               

        ]);

    }
}

Solution

  • I think you used wrong sender config, to set the sender just set MAIL_FROM_ADDRESS on .env like below:

    MAIL_FROM_ADDRESS=your@domain.com
    MAIL_FROM_NAME="${APP_NAME}"
    

    or you can using ->from() method :

    Mail::to($email)->from('youremail@hosting.com')->send(new NewUserWelcomeMail());