My email cron is not working when i trying to run cron for day email send to perticular user

`Hello I’m working on cron in laravel projectin this i want to send some details from database to perticular user every day morning 10AM but when i run command php artisan daily-stats-email-notification:cron it not send any mail
Below I provide you some sample code please help me in this

Below is my Cron file —

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
namespace AppConsoleCommands;
use IlluminateConsoleCommand;
use AppModelsDeptProjectMasterDao;
use AppModelsProjectContactMasterDao;
use AppModelsBroadcastDao;
use AppModelsCampaignMasterDao;
use AppServicesCommonFunction;
use AppModelsConfigurationDao;
use AppModelsCronServicesDao;
class DailyStatsEmailNotificationCron extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'daily-stats-email-notification:cron';
/**
* 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 int
*/
public function handle()
{
$obj = new BroadcastDao();
$pobj = new ProjectContactMasterDao();
$campignobj = new CampaignMasterDao();
$deptObj = new DeptProjectMasterDao();
$cobj = new ConfigurationDao();
$cronObj = new CronServicesDao();
$config = $cobj->loadConfig();
$emails = [];
$end = date("Y-m-d");
$start = date('Y-m-d');
$records = $obj->getRows(["((TO_CHAR(entrytime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."') OR (TO_CHAR(schedule_datetime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."'))"]);
// Checkpoint: Log the number of records fetched
Log::info('Number of records fetched: ' . count($records));
if(is_object($records) && is_countable($records) && count($records) > 0){
foreach($records as $record){
$campaignRec = $campignobj->getRows(["id='".$record->campaign_parent_id."'"]);
// Log campaign records
Log::info('Campaign records: ' . json_encode($campaignRec));
if(is_object($campaignRec) && is_countable($campaignRec) && count($campaignRec) > 0){
foreach($campaignRec as $campaignRecord){
if(property_exists($record,'sent')){
$emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Sent'][] = $record->sent;
}
if(property_exists($record,'delivered')){
$emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Delivered'][] = $record->delivered;
}
if(property_exists($record,'dbtick')){
$emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Read'][] = $record->dbtick;
}
if(property_exists($record,'failed')){
$emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Failed'][] = $record->failed;
}
}
}
}
// Checkpoint: Log the content of the emails array
Log::info('Contents of the emails array: ' . json_encode($emails));
if(is_array($emails) && is_countable($emails) && count($emails) > 0){
$cronObj->addEditRecord(['service_name' => "'".$this->signature."'", 'status' => 1, 'running_time' => "'".date("Y-m-d H:i:s")."'"],0);
$cronInsertedId = $cronObj->insertedid;
foreach($emails as $deptid => $newArray){
if(is_array($newArray) && is_countable($newArray) && count($newArray) > 0){
foreach($newArray as $projectid => $new_Array){
$projectObject = $pobj->getRows(["projectid='".$projectid."'"]);
// Checkpoint: Log the number of project records fetched
Log::info('Number of project records fetched: ' . count($projectObject));
$projectTitle = CommonFunction::getRecordById("AppModelsDeptProjectMasterDao",$projectid);
$deptObject = $deptObj->getRecordById($deptid);
if(is_object($projectObject) && is_countable($projectObject) && count($projectObject) > 0){
foreach($projectObject as $project_Object){
if($project_Object->email != ''){
// $to = $project_Object->email;
$to = "[email protected]";
Log::info("Email address: $to");
$title = $config['COMPANY_NAME'];
$subject = "Today's stats summary report";
$message = "<p>Hello ".$project_Object->name.",</p>";
$message .= "<p>Today's stats summary report - (".date('d-m-Y').")</p>";
$message .= "<p>Department: ".$deptObject->department_title."</p>";
$message .= "<p>Project: ".$projectTitle."</p>";
// Checkpoint: Log the email message
Log::info('Email message: ' . $message);
// Checkpoint: Log email sending status
Log::info('Attempting to send email...');
if(array_key_exists('Sent',$new_Array)){
$message .= "<p>Total Sent: ".array_sum($new_Array['Sent'])."</p>";
}
if(array_key_exists('Delivered',$new_Array)){
$message .= "<p>Total Delivered: ".array_sum($new_Array['Delivered'])."</p>";
}
if(array_key_exists('Read',$new_Array)){
$message .= "<p>Total Read: ".array_sum($new_Array['Read'])."</p>";
}
if(array_key_exists('Failed',$new_Array)){
$message .= "<p>Total Failed: ".array_sum($new_Array['Failed'])."</p>";
}
$setup = array('title' => $title);
$response = CommonFunction::sendEmail($to,$subject,$message,$setup);
if($response){
$cronObj->addEditRecord(['status' => 2, 'completed_time' => "'".date("Y-m-d H:i:s")."'"],$cronInsertedId);
Log::info("Today's stats summary report email has been sent to ".$project_Object->email);
}
else{
Log::info("Today's stats summary report email has not been sent to ".$project_Object->email);
}
}
}
}
}
}
}
}
}
}
}
</code>
<code><?php namespace AppConsoleCommands; use IlluminateConsoleCommand; use AppModelsDeptProjectMasterDao; use AppModelsProjectContactMasterDao; use AppModelsBroadcastDao; use AppModelsCampaignMasterDao; use AppServicesCommonFunction; use AppModelsConfigurationDao; use AppModelsCronServicesDao; class DailyStatsEmailNotificationCron extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'daily-stats-email-notification:cron'; /** * 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 int */ public function handle() { $obj = new BroadcastDao(); $pobj = new ProjectContactMasterDao(); $campignobj = new CampaignMasterDao(); $deptObj = new DeptProjectMasterDao(); $cobj = new ConfigurationDao(); $cronObj = new CronServicesDao(); $config = $cobj->loadConfig(); $emails = []; $end = date("Y-m-d"); $start = date('Y-m-d'); $records = $obj->getRows(["((TO_CHAR(entrytime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."') OR (TO_CHAR(schedule_datetime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."'))"]); // Checkpoint: Log the number of records fetched Log::info('Number of records fetched: ' . count($records)); if(is_object($records) && is_countable($records) && count($records) > 0){ foreach($records as $record){ $campaignRec = $campignobj->getRows(["id='".$record->campaign_parent_id."'"]); // Log campaign records Log::info('Campaign records: ' . json_encode($campaignRec)); if(is_object($campaignRec) && is_countable($campaignRec) && count($campaignRec) > 0){ foreach($campaignRec as $campaignRecord){ if(property_exists($record,'sent')){ $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Sent'][] = $record->sent; } if(property_exists($record,'delivered')){ $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Delivered'][] = $record->delivered; } if(property_exists($record,'dbtick')){ $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Read'][] = $record->dbtick; } if(property_exists($record,'failed')){ $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Failed'][] = $record->failed; } } } } // Checkpoint: Log the content of the emails array Log::info('Contents of the emails array: ' . json_encode($emails)); if(is_array($emails) && is_countable($emails) && count($emails) > 0){ $cronObj->addEditRecord(['service_name' => "'".$this->signature."'", 'status' => 1, 'running_time' => "'".date("Y-m-d H:i:s")."'"],0); $cronInsertedId = $cronObj->insertedid; foreach($emails as $deptid => $newArray){ if(is_array($newArray) && is_countable($newArray) && count($newArray) > 0){ foreach($newArray as $projectid => $new_Array){ $projectObject = $pobj->getRows(["projectid='".$projectid."'"]); // Checkpoint: Log the number of project records fetched Log::info('Number of project records fetched: ' . count($projectObject)); $projectTitle = CommonFunction::getRecordById("AppModelsDeptProjectMasterDao",$projectid); $deptObject = $deptObj->getRecordById($deptid); if(is_object($projectObject) && is_countable($projectObject) && count($projectObject) > 0){ foreach($projectObject as $project_Object){ if($project_Object->email != ''){ // $to = $project_Object->email; $to = "[email protected]"; Log::info("Email address: $to"); $title = $config['COMPANY_NAME']; $subject = "Today's stats summary report"; $message = "<p>Hello ".$project_Object->name.",</p>"; $message .= "<p>Today's stats summary report - (".date('d-m-Y').")</p>"; $message .= "<p>Department: ".$deptObject->department_title."</p>"; $message .= "<p>Project: ".$projectTitle."</p>"; // Checkpoint: Log the email message Log::info('Email message: ' . $message); // Checkpoint: Log email sending status Log::info('Attempting to send email...'); if(array_key_exists('Sent',$new_Array)){ $message .= "<p>Total Sent: ".array_sum($new_Array['Sent'])."</p>"; } if(array_key_exists('Delivered',$new_Array)){ $message .= "<p>Total Delivered: ".array_sum($new_Array['Delivered'])."</p>"; } if(array_key_exists('Read',$new_Array)){ $message .= "<p>Total Read: ".array_sum($new_Array['Read'])."</p>"; } if(array_key_exists('Failed',$new_Array)){ $message .= "<p>Total Failed: ".array_sum($new_Array['Failed'])."</p>"; } $setup = array('title' => $title); $response = CommonFunction::sendEmail($to,$subject,$message,$setup); if($response){ $cronObj->addEditRecord(['status' => 2, 'completed_time' => "'".date("Y-m-d H:i:s")."'"],$cronInsertedId); Log::info("Today's stats summary report email has been sent to ".$project_Object->email); } else{ Log::info("Today's stats summary report email has not been sent to ".$project_Object->email); } } } } } } } } } } } </code>
<?php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use AppModelsDeptProjectMasterDao;
use AppModelsProjectContactMasterDao;
use AppModelsBroadcastDao;
use AppModelsCampaignMasterDao;
use AppServicesCommonFunction;
use AppModelsConfigurationDao;
use AppModelsCronServicesDao;

class DailyStatsEmailNotificationCron extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'daily-stats-email-notification:cron';

    /**
     * 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 int
     */
    public function handle()
    {
        $obj = new BroadcastDao();       
        $pobj = new ProjectContactMasterDao();
        $campignobj = new CampaignMasterDao();
        $deptObj = new DeptProjectMasterDao();
        $cobj = new ConfigurationDao();
        $cronObj = new CronServicesDao();

        $config = $cobj->loadConfig();
        $emails = [];
        $end = date("Y-m-d");
        $start = date('Y-m-d');
        $records = $obj->getRows(["((TO_CHAR(entrytime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."') OR (TO_CHAR(schedule_datetime,'YYYY-MM-DD') BETWEEN '".$start."' AND '".$end."'))"]);

        // Checkpoint: Log the number of records fetched
        Log::info('Number of records fetched: ' . count($records));

        if(is_object($records) && is_countable($records) && count($records) > 0){
            foreach($records as $record){
                $campaignRec = $campignobj->getRows(["id='".$record->campaign_parent_id."'"]);

                 // Log campaign records
                Log::info('Campaign records: ' . json_encode($campaignRec));


                if(is_object($campaignRec) && is_countable($campaignRec) && count($campaignRec) > 0){
                    foreach($campaignRec as $campaignRecord){
                        if(property_exists($record,'sent')){
                            $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Sent'][] = $record->sent;
                        }
                        if(property_exists($record,'delivered')){
                            $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Delivered'][] = $record->delivered;
                        }
                        if(property_exists($record,'dbtick')){
                            $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Read'][] = $record->dbtick;
                        }
                        if(property_exists($record,'failed')){
                            $emails[$campaignRecord->dept_id][$campaignRecord->dept_prj_id]['Failed'][] = $record->failed;
                        }
                    }
                }
            }

                // Checkpoint: Log the content of the emails array
            Log::info('Contents of the emails array: ' . json_encode($emails));

            if(is_array($emails) && is_countable($emails) && count($emails) > 0){
                $cronObj->addEditRecord(['service_name' => "'".$this->signature."'", 'status' => 1, 'running_time' => "'".date("Y-m-d H:i:s")."'"],0);
                $cronInsertedId = $cronObj->insertedid;

                foreach($emails as $deptid => $newArray){
                    if(is_array($newArray) && is_countable($newArray) && count($newArray) > 0){
                        foreach($newArray as $projectid => $new_Array){
                            $projectObject = $pobj->getRows(["projectid='".$projectid."'"]);

                            // Checkpoint: Log the number of project records fetched
                            Log::info('Number of project records fetched: ' . count($projectObject));

                            $projectTitle = CommonFunction::getRecordById("AppModelsDeptProjectMasterDao",$projectid);
                            $deptObject = $deptObj->getRecordById($deptid);
                            if(is_object($projectObject) && is_countable($projectObject) && count($projectObject) > 0){
                                foreach($projectObject as $project_Object){
                                    if($project_Object->email != ''){
                                        // $to = $project_Object->email;
                                        $to = "[email protected]";
                                        Log::info("Email address: $to");
                                       
                                        $title = $config['COMPANY_NAME'];
                                        $subject = "Today's stats summary report";
                                        $message = "<p>Hello ".$project_Object->name.",</p>";
                                        $message .= "<p>Today's stats summary report - (".date('d-m-Y').")</p>";
                                        $message .= "<p>Department: ".$deptObject->department_title."</p>";
                                        $message .= "<p>Project: ".$projectTitle."</p>";
                                         // Checkpoint: Log the email message
                                Log::info('Email message: ' . $message);

                                // Checkpoint: Log email sending status
                                Log::info('Attempting to send email...');
                                        if(array_key_exists('Sent',$new_Array)){
                                            $message .= "<p>Total Sent: ".array_sum($new_Array['Sent'])."</p>";
                                        }
                                        if(array_key_exists('Delivered',$new_Array)){
                                            $message .= "<p>Total Delivered: ".array_sum($new_Array['Delivered'])."</p>";
                                        }
                                        if(array_key_exists('Read',$new_Array)){
                                            $message .= "<p>Total Read: ".array_sum($new_Array['Read'])."</p>";
                                        }
                                        if(array_key_exists('Failed',$new_Array)){
                                            $message .= "<p>Total Failed: ".array_sum($new_Array['Failed'])."</p>";
                                        }
                                        $setup = array('title' => $title);

                                        $response = CommonFunction::sendEmail($to,$subject,$message,$setup);
                                       
                                        if($response){
                                            $cronObj->addEditRecord(['status' => 2, 'completed_time' => "'".date("Y-m-d H:i:s")."'"],$cronInsertedId);
                                            Log::info("Today's stats summary report email has been sent to ".$project_Object->email);
                                        }
                                        else{
                                            Log::info("Today's stats summary report email has not been sent to ".$project_Object->email);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}    

in kernal.php–
$schedule->command(‘daily-stats-email-notification:cron’)->dailyAt(’23:45′);

in my cron file when i run command i get data from database Log::info(‘Campaign records: ‘ . json_encode($campaignRec)); this log give me record but when i come to Log::info(‘Contents of the emails array: ‘ . json_encode($emails)); this log it empty and below all logs are empty i don’n know what is wrong in it `

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật