master
cody 1 day ago
parent aa5bf5fd2c
commit a571e30dd2

@ -0,0 +1,65 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class TestEmailCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:email';
/**
* The console command description.
*
* @var string
*/
protected $description = '测试邮件发送功能是否正常';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// 写死的收件人地址
$to = 'tanyuan@langye.net';
$subject = '系统测试邮件';
$content = '这是一封测试邮件,用于验证邮件发送功能是否正常工作。';
$this->info("开始测试邮件发送功能...");
$this->info("收件人: {$to}");
$this->info("主题: {$subject}");
try {
// 临时设置为 log 驱动进行测试
$originalMailer = config('mail.default');
config(['mail.default' => 'log']);
// 使用 Laravel 的 Mail 门面发送邮件
Mail::raw($content, function ($message) use ($to, $subject) {
$message->to($to)->subject($subject);
});
// 恢复原始配置
config(['mail.default' => $originalMailer]);
$this->info("✅ 邮件发送成功!");
$this->info("邮件已记录到日志文件中,请检查 storage/logs/laravel.log");
return Command::SUCCESS;
} catch (\Exception $e) {
$this->error("❌ 邮件发送失败!");
$this->error("错误信息: " . $e->getMessage());
return Command::FAILURE;
}
}
}

@ -7,7 +7,6 @@ use App\Helpers\ResponseCode;
use App\Helpers\StarterResponseCode;
use App\Jobs\SendCourseCar;
use App\Jobs\SendCourseDoor;
use App\Models\AppointmentTotalLog;
use App\Models\Course;
use App\Models\CourseAppointmentTotal;
use App\Models\CourseForm;

Loading…
Cancel
Save