Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Deadly_Smile's avatar

"An email must have a "To", "Cc", or "Bcc" header." -error in laravel - 10

Hi

I want to send emails from laravel to verify users by email but I am stuck at this error. I can not find any solution for laravel version 10. My codes are:

UserController.php (Controller class)

 public function store(SignUpRequest $request)    {
        $newUser = new User();
        $newUser->username = $request["username"];
        $newUser->name = $request["name"];
        $newUser->email = $request["email"];
        $newUser->password = bcrypt($request["password"]);
        $mailData = [
            "to" => "$newUser->mail",
            "name" => $newUser->name,
            "link" => "http://localhost:5173",
        ];
        $success = Mail::to($newUser->mail)->send(new SignUpMail($mailData));
        return response()->json($success);
}

SignUpMail.php (Mailable class)

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class SignUpMail extends Mailable
{
    use Queueable, SerializesModels;
    public $mailData;
    /**
     * Create a new message instance.
     */
    public function __construct($mailData)
    {
        $this->mailData = $mailData;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            to: [$this->mailData['to']],
            from: new Address("[email protected]"),
            subject: 'Sign Up Mail',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'mails.signupmailvarification',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}

I looked but all I find is this link which is for laravel 9 where build method is used in Mailable class. I am new at this so can anyone help me on this?

PS: I want to learn how to do this in the latest version.

0 likes
6 replies
Snapey's avatar
Snapey
Best Answer
Level 122

This seems wrong

Mail::to($newUser->mail)

did you mean

Mail::to($newUser->email)
1 like
Deadly_Smile's avatar

@Snapey thanks for catching the error. I can't believe I have been stuck for 2 hours for this silly mistake. Thanks again

Snapey's avatar

and this

        $mailData = [
            "to" => "$newUser->mail",
            "name" => $newUser->name,
            "link" => "http://localhost:5173",

I think you should have

        $mailData = [
            "to" => $newUser->email,
            "name" => $newUser->name,
            "link" => config('app.url'),

but that last line should be the route to the validation?

1 like
Deadly_Smile's avatar

@Snapey

"link" => config('app.url'),

I did not know, I guess I need more time learning this staff.

Snapey's avatar

@Deadly_Smile The important thing is that you don't need to change your code when you deploy to a server

Deadly_Smile's avatar

@Snapey I was testing so temporarily I added my front-end link. Letter I would add a verification link, sorry for the misdirection.

Please or to participate in this conversation.