Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过托管服务器通过laravel任务调度器自动发送提醒电子邮件_Php_Laravel_Task_Scheduler - Fatal编程技术网

Php 通过托管服务器通过laravel任务调度器自动发送提醒电子邮件

Php 通过托管服务器通过laravel任务调度器自动发送提醒电子邮件,php,laravel,task,scheduler,Php,Laravel,Task,Scheduler,我想向收到日期在3天后到期的供应商发送一封提醒电子邮件 因此,我创建了一个email:send命令,在其中输入验证码,然后发送电子邮件。然后在文件command/kernel.php中,我每分钟执行我的命令email:send 电子邮件:命令逻辑 $data = $this->mailRep->getCommandes(); $current_date = Carbon::now(); $current_date = $current_date->addDays(3); $cu

我想向收到日期在3天后到期的供应商发送一封提醒电子邮件

因此,我创建了一个
email:send
命令,在其中输入验证码,然后发送电子邮件。然后在文件
command/kernel.php
中,我每分钟执行我的命令
email:send

电子邮件:命令逻辑

$data = $this->mailRep->getCommandes();
$current_date = Carbon::now();
$current_date = $current_date->addDays(3);
$current_date = $current_date->toDateString(); 
$mail_directrice = "souley27souley@gmail.com";

foreach($data as $commande ){
        if($commande->available_date === $current_date){
            $com = array("date" => $commande->available_date,"fournisseur" => $commande->fournisseur);

            Mail::to($commande->responsableEmail)
                ->cc([$commande->responsableEmail,$mail_directrice])
                ->send(new reminderMail($com,'Available'));
        } elseif ($commande->start_send_date === $current_date) {

            $com = array("date" => $commande->start_send_date,"fournisseur" => $commande->fournisseur);

            Mail::to($commande->responsableEmail)
                ->cc([$commande->responsableEmail,$mail_directrice])
                ->send(new reminderMail($com,'start send'));
        } elseif ($commande->arrive_at_port_date === $current_date) {

            $com = array("date" => $commande->arrive_at_port_date,"fournisseur" => $commande->fournisseur);

            Mail::to($commande->fournisseurEmail)
                ->cc([$commande->responsableEmail,$mail_directrice])
                ->send(new reminderMail($com,'Arrive au port'));
        } elseif ($commande->arrive_at_ouaga_date === $current_date) {

            $com = array("date" => $commande->arrive_at_ouaga_date,"fournisseur" => $commande->fournisseur);

            Mail::to($commande->responsableEmail)
                ->cc([$commande->responsableEmail,$mail_directrice])
                ->send(new reminderMail($com,'Arrive a ouaga'));
        } else {
            $this->info("No mail to send !");
        }
    }
提醒邮件类:

class reminderMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;

/**
 * Create a new message instance.
 *
 * @return void
 */
public $viewData;
public $type;
public $mails;
public function __construct($datas,$type)
{
    $this->viewData = $datas;
    $this->type = $type;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from("info@groupekyba.com","PPI/Trakng-control")
        ->with(['commandes' =>$this->viewData, 'type' => $this->type])
        ->view('emails.emails');
}
}
command/kernel.php内容

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

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
     $schedule->command('email:send --force')
              ->everyMinute();
}

/**
 * Register the commands for the application.
 *
 * @return void
 */
protected function commands()
{
    $this->load(__DIR__.'/Commands');

    require base_path('routes/console.php');
}

当我在windows命令提示符下手动执行命令时,一切都很顺利。邮件已发送。现在我已经将我的项目上传到hostinger,在那里我创建了一个cron作业,它每分钟运行一次我的订单。但是,cron作业正常运行,但邮件不会发送。

是否使用任何形式的队列?如果是这样的话,请记住Horizon或supervisorctl之类的软件可能需要重新启动以获取对代码的更改。谢谢您的回答。我不知道我是否理解你的问题,但我实际上已经在我的提醒邮件类上实现了ShouldQueue,这在我的任务执行过程中会造成问题吗?真的很抱歉!!再次感谢您的回复,我想会的,因为这会通知拉威尔工作应该排队。这意味着应用程序将发送作业,因此将创建一个队列(默认值将在you.env文件中设置)。如果您有访问权限,请尝试运行php artisan队列:工作并查看它们是否运行。如果你不想让他们排队,那么你需要删除队列指令我删除了ShouldQueue的实现,但它总是一样的?