userExpireWarningToday.php 785 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Mail;
  3. use App\Models\NotificationLog;
  4. use Exception;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Mail\Mailable;
  8. use Illuminate\Queue\SerializesModels;
  9. class userExpireWarningToday extends Mailable implements ShouldQueue
  10. {
  11. use Queueable, SerializesModels;
  12. protected $id; // 邮件记录ID
  13. public function __construct($id)
  14. {
  15. $this->id = $id;
  16. }
  17. public function build(): userExpireWarningToday
  18. {
  19. return $this->view('emails.userExpireWarningToday')->subject('账号过期提醒');
  20. }
  21. // 发件失败处理
  22. public function failed(Exception $e): void
  23. {
  24. NotificationLog::whereId($this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  25. }
  26. }