newTicket.php 976 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Mail;
  3. use App\Http\Models\EmailLog;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Mail\Mailable;
  6. use Illuminate\Queue\SerializesModels;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. class newTicket extends Mailable implements ShouldQueue
  9. {
  10. use Queueable, SerializesModels;
  11. protected $id; // 邮件记录ID
  12. protected $title; // 工单标题
  13. protected $content; // 工单内容
  14. public function __construct($id, $title, $content)
  15. {
  16. $this->id = $id;
  17. $this->title = $title;
  18. $this->content = $content;
  19. }
  20. public function build()
  21. {
  22. return $this->view('emails.newTicket')->subject('新工单提醒')->with([
  23. 'title' => $this->title,
  24. 'content' => $this->content
  25. ]);
  26. }
  27. // 发件失败处理
  28. public function failed(\Exception $e)
  29. {
  30. EmailLog::query()->where('id', $this->id)->update(['status' => -1, 'error' => $e->getMessage()]);
  31. }
  32. }