My cron is not running

Asked

Viewed 427 times

0

I’m trying to make a cron in the Standard to send an email every 1 minute, but no e-mail has been sent so far.

Man Emailadocaocron.php:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\animalAdocao;
use Mail;


class EmailAdocaoCron extends Command
{

    protected $signature = 'example:cron';
    protected $description = 'Command E-mail';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        $animaisAdocao = animalAdocao::all();
        for($i = 0; $i < count($animaisAdocao); $i++){

            $data = array(
                'apelido' => $animaisAdocao[$i]['apelido']
            );

            Mail::send('emailadocaoconfirmacao', $data, function ($message) use ($animaisAdocao, $i){
                $message->from('[email protected]', 'Ei, email teste')->subject('Confirmação do seu anúncio');
                $message->to($animaisAdocao[$i]['email_contato']);
            });
        }
    }
}

My kernel.php:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    protected $commands = [
        Commands\EmailAdocaoCron::class
    ];

    protected function schedule(Schedule $schedule)
    {
         $schedule->command('example:cron')->everyMinute();
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

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

Something is missing?

This is my table where I pick up the emails to send:

inserir a descrição da imagem aqui

  • configured SMTP shipping service?

  • Yes, I got it, you have to create a file . bat and use with xampp

1 answer

1


Try running in the terminal of your project: php Artisan example:cron and see if there is an error. If there is an error, it is correct what is wrong.

In parallel, in order for crons to work, it is necessary to add a cron to the server where the application is hosted, that is, to the write terminal:

crontab -e

and add the following line (Changing the names to the correct ones)

 * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

More information here: https://laravel.com/docs/5.8/scheduling#Introduction

  • I did something similar, I used shaman to run the cron

Browser other questions tagged

You are not signed in. Login or sign up in order to post.