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

vinschi's avatar
Level 16

Sending an email to multiple users

Hi, I need to send an email to more than one user (admin and the user who created the model) every time a specific model is created. To do this, I created this function inside the model:

public function sendMail( User $user)
    {
        $admin = new User;
        $admin ->email = '[email protected]';
    \Mail::to($user)->cc($admin)->send(new Welcome($user));
        flash('Email sent.','success');
    }

Am I doing something wrong? Thanks

0 likes
3 replies
EventFellows's avatar

what is not working? looks ok despite hardcoding the admin in that method.

you can also put in an email directly to the CC.

you might want to think about queing for performance reasons.

1 like
martinbean's avatar

@vinschi I’m with @EventFellows: you’ll want to queue this. You don’t want to slow your application down because it needs to send emails every time a model’s created.

You could hook into the model’s created and queue your email there:

class Foo extends Model
{
    public static function boot()
    {
        parent::boot();

        static::created(function ($model) {
            dispatch(new ModelCreated($model));
        });
    }
}

The job would then send the email when processed by a queue worker:

class ModelCreated implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $model;

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

    public function handle()
    {
        $admin = '[email protected]';

        Mail::to($model->user)
            ->cc($admin)
            ->send(new ModelCreatedMail($model));
    }
}

Please or to participate in this conversation.