領収証発行サービス
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

43 řádky
986B

  1. <?php
  2. namespace App\Email;
  3. use App\Models\Email;
  4. use App\Util\DateUtil;
  5. use Exception;
  6. use Illuminate\Support\Facades\Log;
  7. use Illuminate\Support\Facades\Mail;
  8. class Sender
  9. {
  10. public static function send(string $emailId)
  11. {
  12. $email = Email::findOrFail($emailId);
  13. info("メール送信", [
  14. 'id' => $email->id,
  15. 'email' => $email->email,
  16. 'mailer' => $email->type,
  17. ]);
  18. try {
  19. Mail::to($email->email)
  20. ->send(new TextEmail($email->subject, $email->content, $email->emailAttachments));
  21. } catch (Exception $e) {
  22. Log::error("メール送信失敗", [
  23. 'id' => $email->id,
  24. 'email' => $email->email,
  25. 'mailer' => $email->type,
  26. ]);
  27. $email->is_failed = true;
  28. $email->save();
  29. throw $e;
  30. }
  31. $email->send_datetime = DateUtil::now();
  32. $email->save();
  33. }
  34. }