sendVerifyCode.php 877 B

1234567891011121314151617181920212223242526272829303132333435
  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 sendVerifyCode extends Mailable implements ShouldQueue
  10. {
  11. use Queueable, SerializesModels;
  12. protected $id; // 邮件记录ID
  13. protected $code; // 要发送的验证码
  14. public function __construct($id, $code)
  15. {
  16. $this->id = $id;
  17. $this->code = $code;
  18. }
  19. public function build(): sendVerifyCode
  20. {
  21. return $this->view('emails.sendVerifyCode')->subject('发送注册验证码')->with(['code' => $this->code]);
  22. }
  23. // 发件失败处理
  24. public function failed(Exception $e): void
  25. {
  26. NotificationLog::whereId($this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  27. }
  28. }