diff --git a/app/Console/Commands/SendEmail.php b/app/Console/Commands/SendEmail.php index 6e0361a..80739c8 100755 --- a/app/Console/Commands/SendEmail.php +++ b/app/Console/Commands/SendEmail.php @@ -58,9 +58,15 @@ class SendEmail extends Command $title = EmailRecordUser::template($records->subject, $recordUser); // 替换后的内容 $template = EmailRecordUser::template($emailTemplate->content, $recordUser); - // 发送邮件 - EmailRecordUser::email($title, $template, $recordUser); - $recordUser->status = 1; + try { + // 发送邮件 + EmailRecordUser::email($title, $template, $recordUser); + $recordUser->status = 1; + } catch (\Exception $e) { + $recordUser->status = 2; + $recordUser->reason = $e->getMessage(); + } + $recordUser->send_time = date('Y-m-d H:i:s'); $recordUser->save(); } } diff --git a/database/migrations/2025_07_04_092918_create_email_record_users_table.php b/database/migrations/2025_07_04_092918_create_email_record_users_table.php index 2ab565f..a02ea65 100644 --- a/database/migrations/2025_07_04_092918_create_email_record_users_table.php +++ b/database/migrations/2025_07_04_092918_create_email_record_users_table.php @@ -23,6 +23,8 @@ return new class extends Migration { $table->tinyInteger('status')->nullable()->default(0)->comment('状态0:待发送1:成功 2:失败'); // 发送时间 $table->dateTime('send_time')->nullable()->comment('发送时间'); + // 原因 + $table->string('reason')->nullable()->comment('原因'); $table->timestamps(); $table->softDeletes(); });