在laravel中发送自动电子邮件

I want to create a procedure which will sent auto email base on a condition.

On my table I have a expire_date column and want to sent auto email to everyone to remind them that their account will expire next week.
I am using laravel and mysql.

Thank You

setup a daily scheduled task that checks users expirations within a week.

in app/Console/kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('notify:expirations')
              ->daily();
}

and make a new artisan command that checks for expirations.

don't forget to set cron job on the server to run php artisan schedule:run every minute

You may use laravel's Mail facade.

Something like

$ten_days_from_now = \Carbon\Carbon::now()->addDay(10);
$users = User::where('expire_date', '<', $ten_days_from_now)->get();

foreach ($users as $user) {
    Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
        $m->from('hello@app.com', 'Your Application');

        $m->to($user->email, $user->name)->subject('Your Reminder!');
    });
}

You can put something like this into a command and execute it with a cron.