不是从命令发送的电子邮件。这是命令代码。
public function handle()
{
Mail::to('[email protected]')->send(new EmailNotification());
}
但是,当我尝试从路由邮件发送邮件时。
Route::get('test_mail', function(){
Mail::to('[email protected]')->send(new EmailNotification());
});
如何从命令行发送电子邮件?当我运行
php artisan send:emailNotification
它没有显示错误
完整的命令代码:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use App\Mail\EmailNotification;
class SendEmailNotification extends Command
{
protected $signature = 'send:emailNotification';
protected $description = 'Send email notifications.';
public function __construct()
{
parent::__construct();
}
public function handle()
{
Mail::to('[email protected]')->send(new EmailNotification());
}
}
您的代码看起来很清晰,但是要检查它有什么问题,我需要整个代码,或者您也可以检查邮件是否不在队列中。如果要进入队列,则需要执行队列。
您也可以尝试发送类似邮件-
Mail::send('birthday', $this->data, function ($message) {
$message->to('[email protected]', 'ExampleName')->subject('Happy Birthday!');
});
在“生日”上方是您的邮件模板,您可以使用.blade创建并将其保存在view文件夹中,而$ this-> data是您在构造函数中传递的数据。