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

AbdulBazith's avatar

Even though cron job deleted mails are receiving php artisan schedule:run

Guys Iam working with a project its online exam system. i added a cron job in my cpanel as cd public_html/my-folder && php artisan schedule:run >> /dev/null 2>&1

and in my project-folder/app/Console kernel.php

  $schedule->command('auto:start')
        ->everyMinute();
        
         $schedule->command('auto:stop')
        ->everyMinute();
        
          $schedule->command('auto:publish')
        ->everyMinute();

i have three files in project-folder/app/Console/Commands

 '\App\Console\Commands\AutoStart',
        '\App\Console\Commands\AutoStop',
        '\App\Console\Commands\AutoPublish',

actually every minute these files should get run and in exams are scheduled in that time exam should be automatically started, stopped and the result should be published. everything working fine.

before the DB query just a added a text mail code and linked my mail. i got the test mail each minute, after that i removed the test mail code. But still iam getting the test mail... i have cleared the cache, removed the cron job everything i dont but still iam getting the test mail. i contacted my cpanel support, they said its issue in the cron job file and need to check that.

So kindly some one suggest to stop the test mail, monthly monthly i will change the project folder, so that i will change the cron job path monthly and will check by the text mail working or not, everything went fine for past 6 months, but from one month back eventhough i remove the test mail code the mails are coming coming. the DB query also working fine.

i did a thing i opened terminal and ran the php artisan schedule:run this query, whether this may be any reason. what should i do now to stop this test mail..

0 likes
28 replies
Sinnbeck's avatar

If you run it manually with php artisan schedule:run do you also get the test email?

AbdulBazith's avatar

@Sinnbeck yes,, past 10 days iam getting that test mail.. but if i delete the cron job, the DB queries are not working. but iam getting the test mail. i did cache, route,config clear, optimize all .. but still iam getting the test mail..

Sinnbeck's avatar

@AbdulBazith Ok. Test the commands one at a time, to see which one triggers the mail

php artisan auto:start
php artisan auto:stop
php artisan auto:publish
AbdulBazith's avatar

@Sinnbeck actually i wrote the text mail for all the three as check1, check2 and check3 in subject. iam getting all the thee check mails. even i removed the test mail and i added a new test mail with date, and then i removed that too, but again and again iam getting both old test mail and the new test mail also

Sinnbeck's avatar

@AbdulBazith That sounds really strange. See if changes are reflected at all. Add dd('works'); in the beginning of one of the commands, and see if that triggers

AbdulBazith's avatar

@Sinnbeck i wrote a dd("test") in all the three and did this

[myserver@server ~]$ cd public_html/
[myserver@server public_html]$ cd my-project-folder/
[myserver@server my-project-folder]$ php artisan auto:start
[myserver@server my-project-folder]$ php artisan auto:stop
[myserver@server my-project-folder]$ php artisan auto:publish
[myserver@server my-project-folder]$ php artisan schedule:run
Running scheduled command: '/opt/cpanel/ea-php74/root/usr/bin/php' 'artisan' auto:start > '/dev/null' 2>&1
Running scheduled command: '/opt/cpanel/ea-php74/root/usr/bin/php' 'artisan' auto:stop > '/dev/null' 2>&1
Running scheduled command: '/opt/cpanel/ea-php74/root/usr/bin/php' 'artisan' auto:publish > '/dev/null' 2>&1
[myserver@server my-project-folder]$

the above is my cpanel terminal code i did

iam unable to identify whats happening, but till now iam getting the test mail

Sinnbeck's avatar

@AbdulBazith So it sounds like the change isnt reflected. Can you type cat app/Console/Commands/AutoStart.php and then see if it is actually in the file there on the server?

AbdulBazith's avatar

@Sinnbeck yes i can see the dd("test") which i put. iam able to see it in the command. and you are saying it isnt reflected. but if remove the cron job the DB queries are not working. but the test mails are comming... and if i add the cron job, db queries are working

AbdulBazith's avatar

@Sinnbeck when i run the cat command

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\StudentExamMain;

use App\AssessmentCreationMain;

class AutoPublish extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto:publish';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Automatic publish Result of Assessments';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {


                 dd("publish");


            $pastdate=date('Y-m-d', strtotime(date('Y-m-d') . ' -1 day'));

        $pasttime=date('H:i',strtotime('-24 hours'));

        // dump($pastdate,$pasttime);

this is what i get in terminal

Sinnbeck's avatar

@AbdulBazith Yeah what we are struggling with is that for some reason php is running and old version of the code it seems.

Sinnbeck's avatar

@AbdulBazith There probably is but as I have never seen that problem before in my life, I cannot easily tell you how. I am currently trying to think of any reason why it would happen.

AbdulBazith's avatar

@Sinnbeck is it possible to stop the run command and after clearing cache shall i run the command again??

even i did like this, removed these three lines from kernel.php

  $schedule->command('auto:start')
        ->everyMinute();
        
         $schedule->command('auto:stop')
        ->everyMinute();
        
          $schedule->command('auto:publish')
        ->everyMinute();

and then i cleared the cache etc, and i ran the schedule run command.. but no response, but the DB queries are not working.. actually the test mail codes are saved somewhere else like cache?? because if i do any change the DB queries not working, but the test mails are receiving

Sinnbeck's avatar

@AbdulBazith Well you are telling me that dd() doesnt even work, so I dont see how this has anything to do with mail? You seem to be focused on the wrong problem? Can you try running php artisan optimize:clear

AbdulBazith's avatar

@Sinnbeck

[myserver@server my-project-folder]$ ^C
[myserver@server my-project-folder]$ php artisan optimize:clear
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!
[myserver@server my-project-folder]$
[myserver@server my-project-folder]$
[myserver@server my-project-folder]$

i ran the command. actually i added dd(), so what would be the response if i run the schedule run command?

i added dd() in all the three files. now what should i need to check and how?

the problem is if do any changes in the cron job, or the files, the DB queries i added not working thats correct. but how come the mails comming after deleting the test mail code

Sinnbeck's avatar

@AbdulBazith Ignore schedule:run for now. If you cannot get php artisan auto:publish to trigger the dd() then start there first. No need to complicate things

AbdulBazith's avatar

@Sinnbeck perfect now the dd's working

[myserver@server my-project-folder]$ php artisan auto:start
"Start"
[myserver@server my-project-folder]$ php artisan auto:stop
"stop"
[myserver@server my-project-folder]$ php artisan auto:publish
"publish"
[myserver@server my-project-folder]$

after this php artisan optimize:clear i think it cleared everything

so what should i do now, to wait for an hour to check whether the test mail coming or not ??

Sinnbeck's avatar

@AbdulBazith Yeah that hopefully did it. Remove the dd() and run php artisan optimize:clear to make sure that it is ready, and then wait and see :)

AbdulBazith's avatar

@Sinnbeck

but still i am getting the test mail... i removed the dd and ran php artisan optimize:clear

but now 12.40 i got the old test mail. what i should do now?? getting much confused...

Sinnbeck's avatar

@AbdulBazith I honestly have no idea. Are you sure that the code for that test mail is no where to be found? Do you use queues at all?

AbdulBazith's avatar

@Sinnbeck only i have 3 files, i deleted the test code from all the 3 files. other than that do i need to check somewhere else??

Do you use queues at all ?? means?? i didnt use any queues.. how can i check this regarding queues??

Sinnbeck's avatar

@AbdulBazith Queues are a way of handling data, like sending mails, in a queue (a background job). Based on your reaction, I assume you dont use queues.

Regarding the 3 files, I dont know your code, so I cannot really give advice. Are you able to recreate the problem locally ?

AbdulBazith's avatar

@Sinnbeck

this is my kernel.php

<?php

namespace App\Console;

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

use App\AssessmentCreationMain;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        '\App\Console\Commands\AutoStart',
        '\App\Console\Commands\AutoStop',
        '\App\Console\Commands\AutoPublish',
    ];

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

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

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

and this is my AutoStart.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\AssessmentCreationMain;



class AutoStart extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto:start';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Atomatic start of Assessments';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        
     
        
                        ini_set( 'display_errors', 1 );
                          error_reporting( E_ALL );
                        $from = "info@server";
                           $to = [email protected]";
                          $subject = "Check start 19-9-22";
                          $message = "Check";
                          $headers = "From:" . $from;
                          mail($to,$subject,$message, $headers);
        
                      
               

          AssessmentCreationMain::where('exam_date',date('Y-m-d'))->where('auto_exam_start_time',date('H:i'))->update([
                    'student_status' => '1',
              'assessment_status' => 'active',
                  ]);

         $maillists=    AssessmentCreationMain::where('exam_date',date('Y-m-d'))->where('auto_exam_start_time',date('H:i'))->get();


         if(count($maillists)!=0)
                      {
                    

                            error_reporting( E_ALL );
                         $from = "info@server";
                           $to = [email protected]";
                            $subject = "Nissimax - Slot 1 Exam Started";
                            
                            $message ="
                            <html>
                            <head></head>
                            <body>
                                <h3>For the Following class , section,  subject slot 1 exam started</h3>
                                <img style='display:block;margin:auto;' src='https://nissimax.com/images/logo.png' alt='Nissmax'>
                                <table rules='all' style='border:2px solid #ddd;border-color: #ddd;' width='100%' cellpadding='10'>
                                    <thead>
                                        <tr style='background: #eee;'>
                                            <th width='10%'> <strong>ClassName</strong></th>
                                            <th><strong>Section</strong></th>
                                            <th><strong>Subject</strong></th>
                                        </tr>
                                    </thead>
                                    <tbody>";
                                        foreach($maillists->groupby("schooldetails.school_name") as $school=>$maillist) {
                                        $message .="
                                        <th colspan='4'> SCHOOL - " .$school. " </th>
                                        ";
                                        foreach ($maillist->groupby("classdetails.class_name") as $classname=>$ccc )
                                        {
                                        $message .="
                                        <tr>
                                            <td> ". $classname." <br><br>
                                                ". date('d-m-Y', strtotime($ccc->pluck('exam_date')->unique()->implode(', '))). "
                                                <br><br>
                                                ".date('h:i:s A', strtotime($ccc->pluck('auto_exam_start_time')->unique()->implode(', '))). "
                                            </td>
                                            <td>".$ccc->pluck('section.section')->implode(' - ')." <br> <br>
                                                Total Section - ". count($ccc) ."
                                            </td>
                                            <td>".$ccc->pluck('subject.sub_name')->unique()->implode(' - ') ." </td>
                                        </tr>";
                                        }
                                        }
                                        $message .= "</tbody>
                                </table>
                                <hr />
                            </body>
                            </html>";
                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                            // Additional headers
                            $headers .= 'From: ' . $from . "\r\n";
                            
                            mail($to,$subject,$message, $headers);



                      }


                      AssessmentCreationMain::where('slot2_exam_date',date('Y-m-d'))->where('slot2_auto_exam_start_time',date('H:i'))->update([
                        'student_status' => '1',
                  'assessment_status' => 'active',
                      ]);

             $maillists=    AssessmentCreationMain::where('slot2_exam_date',date('Y-m-d'))->where('slot2_auto_exam_start_time',date('H:i'))->get();


             if(count($maillists)!=0)
                          {
                            
                                error_reporting( E_ALL );
                            $from = "info@server";
                           $to = [email protected]";
                                $subject = "Nissimax - Slot 2 Exam Started";
                                
                                $message ="
                                <html>
                                <head></head>
                                <body>
                                    <h3>For the Following class , section,  subject Slot 2 exam started</h3>
                                    <img style='display:block;margin:auto;' src='https://nissimax.com/images/logo.png' alt='Nissmax'>
                                    <table rules='all' style='border:2px solid #ddd;border-color: #ddd;' width='100%' cellpadding='10'>
                                        <thead>
                                            <tr style='background: #eee;'>
                                                <th width='10%'> <strong>ClassName</strong></th>
                                                <th><strong>Section</strong></th>
                                                <th><strong>Subject</strong></th>
                                            </tr>
                                        </thead>
                                        <tbody>";
                                            foreach($maillists->groupby("schooldetails.school_name") as $school=>$maillist) {
                                            $message .="
                                            <th colspan='4'> SCHOOL - " .$school. " </th>
                                            ";
                                            foreach ($maillist->groupby("classdetails.class_name") as $classname=>$ccc )
                                            {
                                            $message .="
                                            <tr>
                                                <td> ". $classname." <br><br>
                                                    ". date('d-m-Y', strtotime($ccc->pluck('slot2_exam_date')->unique()->implode(', '))). "
                                                    <br><br>
                                                    ".date('h:i:s A', strtotime($ccc->pluck('slot2_auto_exam_start_time')->unique()->implode(', '))). "
                                                </td>
                                                <td>".$ccc->pluck('section.section')->implode(' - ')." <br> <br>
                                                    Total Section - ". count($ccc) ."
                                                </td>
                                                <td>".$ccc->pluck('subject.sub_name')->unique()->implode(' - ') ." </td>
                                            </tr>";
                                            }
                                            }
                                            $message .= "</tbody>
                                    </table>
                                    <hr />
                                </body>
                                </html>";
                                $headers = "MIME-Version: 1.0" . "\r\n";
                                $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                                // Additional headers
                                $headers .= 'From: ' . $from . "\r\n";
                                
                                mail($to,$subject,$message, $headers);




                          }



    }
}


and this is my AutoStop.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\AssessmentCreationMain;

class AutoStop extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto:stop';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Automatic stop of Assessments';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

  

                


         AssessmentCreationMain::where('exam_end_date',date('Y-m-d'))->where('auto_exam_stop_time',date('H:i'))->update([
            'assessment_status' => 'inactive',
            'student_status' => 0,

                  ]);

                  $maillists=    AssessmentCreationMain::where('exam_end_date',date('Y-m-d'))->where('auto_exam_stop_time',date('H:i'))->get();


                    if(count($maillists)!=0)
                      {
                       
                          error_reporting( E_ALL );
                            $from = "info@server";
                           $to = [email protected]";
                            $subject = "Nissimax - Slot 1 Exam Stopped";
                            
                            $message ="
                            <html>
                            <head></head>
                            <body>
                                <h3>For the Following class , section,  subject slot 1 exam Stopped</h3>
                                <img style='display:block;margin:auto;' src='https://nissimax.com/images/logo.png' alt='Nissmax'>
                                <table rules='all' style='border:2px solid #ddd;border-color: #ddd;' width='100%' cellpadding='10'>
                                    <thead>
                                        <tr style='background: #eee;'>
                                            <th width='10%'> <strong>ClassName</strong></th>
                                            <th><strong>Section</strong></th>
                                            <th><strong>Subject</strong></th>
                                        </tr>
                                    </thead>
                                    <tbody>";
                                        foreach($maillists->groupby("schooldetails.school_name") as $school=>$maillist) {
                                        $message .="
                                        <th colspan='4'> SCHOOL - " .$school. " </th>
                                        ";
                                        foreach ($maillist->groupby("classdetails.class_name") as $classname=>$ccc )
                                        {
                                        $message .="
                                        <tr>
                                            <td> ". $classname." <br><br>
                                                ". date('d-m-Y', strtotime($ccc->pluck('exam_end_date')->unique()->implode(', '))). "
                                                <br><br>
                                                ".date('h:i:s A', strtotime($ccc->pluck('auto_exam_stop_time')->unique()->implode(', '))). "
                                            </td>
                                            <td>".$ccc->pluck('section.section')->implode(' - ')." <br> <br>
                                                Total Section - ". count($ccc) ."
                                            </td>
                                            <td>".$ccc->pluck('subject.sub_name')->unique()->implode(' - ') ." </td>
                                        </tr>";
                                        }
                                        }
                                        $message .= "</tbody>
                                </table>
                                <hr />
                            </body>
                            </html>";
                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                            // Additional headers
                            $headers .= 'From: ' . $from . "\r\n";
                            
                            mail($to,$subject,$message, $headers);
                        
                        
                         }

                            /*  Slot 2 Option */

                      AssessmentCreationMain::where('slot2_exam_end_date',date('Y-m-d'))->where('slot2_auto_exam_stop_time',date('H:i'))->update([
                        'assessment_status' => 'inactive',
                         'student_status' => 1,

                      ]);

                      $maillists=    AssessmentCreationMain::where('slot2_exam_end_date',date('Y-m-d'))->where('slot2_auto_exam_stop_time',date('H:i'))->get();


                        if(count($maillists)!=0)
                          {
                            
                             error_reporting( E_ALL );
                            $from = "[email protected]";
                         $to = "[email protected]";
                            $subject = "Nissimax - Slot 2 Exam Completed";
                            
                            $message ="
                            <html>
                            <head></head>
                            <body>
                                <h3>For the Following class , section,  subject slot 2 exam Completed</h3>
                                <img style='display:block;margin:auto;' src='https://nissimax.com/images/logo.png' alt='Nissmax'>
                                <table rules='all' style='border:2px solid #ddd;border-color: #ddd;' width='100%' cellpadding='10'>
                                    <thead>
                                        <tr style='background: #eee;'>
                                            <th width='10%'> <strong>ClassName</strong></th>
                                            <th><strong>Section</strong></th>
                                            <th><strong>Subject</strong></th>
                                        </tr>
                                    </thead>
                                    <tbody>";
                                        foreach($maillists->groupby("schooldetails.school_name") as $school=>$maillist) {
                                        $message .="
                                        <th colspan='4'> SCHOOL - " .$school. " </th>
                                        ";
                                        foreach ($maillist->groupby("classdetails.class_name") as $classname=>$ccc )
                                        {
                                        $message .="
                                        <tr>
                                            <td> ". $classname." <br><br>
                                                ". date('d-m-Y', strtotime($ccc->pluck('slot2_exam_end_date')->unique()->implode(', '))). "
                                                <br><br>
                                                ".date('h:i:s A', strtotime($ccc->pluck('slot2_auto_exam_stop_time')->unique()->implode(', '))). "
                                            </td>
                                            <td>".$ccc->pluck('section.section')->implode(' - ')." <br> <br>
                                                Total Section - ". count($ccc) ."
                                            </td>
                                            <td>".$ccc->pluck('subject.sub_name')->unique()->implode(' - ') ." </td>
                                        </tr>";
                                        }
                                        }
                                        $message .= "</tbody>
                                </table>
                                <hr />
                            </body>
                            </html>";
                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                            // Additional headers
                            $headers .= 'From: ' . $from . "\r\n";
                            
                            mail($to,$subject,$message, $headers);


                          }
    }
}


and this is my AutoPublish.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\StudentExamMain;

use App\AssessmentCreationMain;

class AutoPublish extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto:publish';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Automatic publish Result of Assessments';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        
          
                       


            $pastdate=date('Y-m-d', strtotime(date('Y-m-d') . ' -1 day'));

        $pasttime=date('H:i',strtotime('-24 hours'));

        // dump($pastdate,$pasttime);

        StudentExamMain::whereHas('assessmentmaindetails', function ($query) use($pastdate,$pasttime) {
            $query->where('auto_exam_start_time', $pasttime)->where('exam_date', $pastdate);
            })->update(['result_status' => '1']);

            AssessmentCreationMain::where('slot2_auto_exam_stop_time', $pasttime)->where('slot2_exam_end_date', $pastdate)->update(['assessment_status' => 'inactive']);

    }
}

and one more thing . iam not getting the test mail each minutes, its randomly coming, may be 15 mins gap i think so.

Sinnbeck's avatar

@AbdulBazith Oh so you arent using laravel to send mails?

mail($to,$subject,$message, $headers);

Havent used that in many years. Mayve you should consider using the built in mail system in laravel with an smtp server?

AbdulBazith's avatar

@Sinnbeck still now iam getting those test mails. but iam not getting the mail each minute,, between gap of 1 hr or like that getting those mails. even after that i have added another test mail code, i got that mail and i removed that, and iam not getting those mails now. but the old test mails are still coming is there any way of clearing cache or something else, else is it possible to rerun the schdule command.

actually the thing is everthing working fine, just the old test mail is the issue here that repeatedly coming..

Sinnbeck's avatar

@AbdulBazith there must be something in your system that is sending it. I don't suppose the project is public on github?

Please or to participate in this conversation.