<?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
You can add logging statements to your scheduled command to help troubleshoot the issue. For example:
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
to write messages to the Laravel log file. This can help you trace the execution of your command and identify any issues.