sendVerifyCode.php 964 B

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