選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

48 行
1.1KB

  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. $bcc = config('mail.bcc_targets', []);
  19. try {
  20. $send = Mail::to($email->email);
  21. if (0 < count($bcc)) {
  22. $send = $send->bcc($bcc);
  23. }
  24. $send->send(new TextEmail($email->subject, $email->content, $email->emailAttachments));
  25. } catch (Exception $e) {
  26. Log::error("メール送信失敗", [
  27. 'id' => $email->id,
  28. 'email' => $email->email,
  29. 'mailer' => $email->type,
  30. ]);
  31. $email->is_failed = true;
  32. $email->save();
  33. throw $e;
  34. }
  35. $email->send_datetime = DateUtil::now();
  36. $email->save();
  37. }
  38. }