skip to Main Content
<?php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use AppUser;
use Mail;

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

    /**
     * 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() {
        $userEmail = User::select('email')->get();

        $emails = [];
        foreach ($userEmail as $each) {
            $emails[] = $each['email'];
        }

        $data = array('name' => "Virat Gandhi");

        Mail::send(['text' => 'mail'], $data, function ($message) use ($emails) {
            $message->to('[email protected]', 'Tutorials Point')->subject('Laravel Basic Testing Mail');
            $message->from('[email protected]', 'Premium Invoicing System');
        });

        echo "Basic Email Sent. Check your inbox.";
    }
}
?>

Cron works but mail does not come, when i hit from route to controller it works, But scheduler does not work, i used the same credentials for browser route hit and scheduler cron jobs

2

Answers


  1. Chosen as BEST ANSWER

    Yes i tried with log::info. No errors. print only scheduler command started and end. Cron job works fine when i used Gmail credentials it works. But i used other credentials it works from browser route, not mail triggered from Cron jobs


  2. You can add logging statements to your scheduled command to help troubleshoot the issue. For example:

    use IlluminateSupportFacadesLog;
    
    // ...
    
    public function handle() {
        Log::info('Scheduled command started');
    
        // ... (your existing code)
    
        Log::info('Scheduled command completed');
    }
    

    To get more information about what might be going wrong, you can add some debugging output to your scheduled command. For example, you can use

    Log::info()
    

    to write messages to the Laravel log file. This can help you trace the execution of your command and identify any issues.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search