限制一次计划任务中发送电子邮件Laravel

时间:2019-04-30 09:41:21

标签: windows laravel email laravel-5 exchange-server

我限制从SMTP交换电子邮件有问题。我有特定表的计数表。总数为201。总数将在服务器上自动发送带有计划任务的电子邮件。

计数总计

enter image description here

使用laravel可以每批发送多达201封电子邮件吗?

cronEmail

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:reminder';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Command description';

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    parent::__construct();
}

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $this->updateMailConfig();
    $check = DB::table('a_kpi')->join('d_mem','k_created_by','m_id')
    ->leftjoin('a_kpid','kd_kpi_id','k_id')
    ->where('k_status_id',1)
    ->where(function($query){
        $query->where('kd_status_id','=','In Progress')
                ->orwhere('kd_status_id','=',null)
                ->orwhere('kd_status_id','=')
                ->orwhere('kd_status_id','=','null')
                ->orwhere('kd_status_id','=',"null");
    })
    ->get();

    $dt = date("Y-m-d");
    $dtdt = date( "Y-m-d", strtotime( "$dt +10 day" ) );
    for ($i=0; $i <count($check); $i++) { 
        if ($check[$i]->kd_duedate == $dtdt) {
           $mail = $check[$i]->m_email;
            Mail::send('mail.tes', 
                ['pesan'         => 'KPI INFORMATION',
                 'k_label'       => $check[$i]->k_label,
                 'kd_tacticalstep'  => $check[$i]->kd_tacticalstep,
                 'kd_duedate'     =>  $check[$i]->kd_duedate], 
            function ($message) use ($mail)
            {
                $message->subject('REMINDER');
                $message->to($mail);
            });


            $data = DB::table('d_log_reminder')
                                    ->insert([
                                    'dlr_id'=>$check[$i]->k_id,
                                    'dlr_kpi_id'=>$check[$i]->k_id,
                                    'dlr_kpid_id'=>$check[$i]->kd_id,
                                    'dlr_tacticalstep'=>$check[$i]->kd_tacticalstep,
                                    'dlr_label'=>$check[$i]->k_label,
                                    'dlr_duedate'=>$check[$i]->kd_duedate,
                                    'dlr_created_by'=>$check[$i]->k_created_by,
                                    'dlr_send_to'=>$mail
                                    ]);


        }
    }


    // $check = DB::table('d_mem')->where('m_username','admin')->update(['m_code'=>'cor'.date('d-m-y h:i:s')]);

}
}

Kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use App\Helper\ConfigUpdater;
use Mail;
use DB;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
    use ConfigUpdater;

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        'App\Console\Commands\cronEmail'
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {


            $schedule->command('email:reminder')
            ->everyMinute();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

0 个答案:

没有答案