tomasosho's avatar

InvalidArgumentException Mailer [mail] is not defined.

When i register a new user

protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'username' => $data['username'],
            'password' => Hash::make($data['password']),
        ]);

        $userRole = Role::select('id')->where('name', 'user')->first();
        $user->roles()->attach($userRole);

        $email = $data['email'];
        
        $data = ([
        'name' => $data['name'],
        'email' => $data['email'],
        'username' => $data['username'],
        ]);
        
        Mail::to($email)->send(new WelcomeMail($data));

        return redirect('/login')->with('message', 'Account created successfully, Congratulations');
    }

Mail

public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $subject = 'Welcome';
        return $this->view('emails.welcome')->subject($subject);
    }
0 likes
6 replies
sr57's avatar

$emails not initialized

before

Mail::to($email)->send(new WelcomeMail($data))

tomasosho's avatar

dd($email) is getting the mail address. if that is what you are saying

sr57's avatar

Yes, it was what I thought.

I don't remember the syntax of Mail::...

Had you double-check this syntax versus the doc?

Have you review your logs? Maybe more precise msg?

1 like
tomasosho's avatar

Error Log

[2021-02-02 17:11:09] local.ERROR: Mailer [mail] is not defined. {"exception":"[object] (InvalidArgumentException(code: 0): Mailer [mail] is not defined. at /home/bitsixpe/afiaprime.com/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php:110)
sr57's avatar

Don't you use 'mail' in your class WelcomeMail? Can you show to review your data?

Maybe

$data = ([
        'name' => $data['name'],
        'mail' => $data['email'],
        'username' => $data['username'],
        ]);
1 like
tomasosho's avatar
tomasosho
OP
Best Answer
Level 4

i had to switch to smtp in my .evn and it worked. Thanks!

Please or to participate in this conversation.