php Laravel 5.4调度器邮件不发送,但没有错误日志

qltillow  于 2023-10-15  发布在  PHP
关注(0)|答案(2)|浏览(102)
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;
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工作,但邮件不来,当我打从路由到控制器它的工作,但调度器不工作,我使用相同的凭据浏览器路由命中和调度器cron作业

ttcibm8c

ttcibm8c1#

您可以将日志记录语句添加到计划命令中,以帮助解决问题。举例来说:

use Illuminate\Support\Facades\Log;

// ...

public function handle() {
    Log::info('Scheduled command started');

    // ... (your existing code)

    Log::info('Scheduled command completed');
}

若要获得有关可能出错的地方的更多信息,可以向计划命令添加一些调试输出。例如,您可以使用

Log::info()

将消息写入Laravel日志文件。这可以帮助您跟踪命令的执行并识别任何问题。

ws51t4hk

ws51t4hk2#

是的,我尝试了log::info。无错误。仅打印调度程序命令开始和结束。当我使用Gmail凭据时,Cron工作正常。但我使用了其他凭据,它从浏览器路由工作,而不是从Cron作业触发的邮件

相关问题