|
- <?php
-
- namespace App\Email;
-
- use App\Models\Email;
- use App\Util\DateUtil;
- use Exception;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Mail;
-
- class Sender
- {
-
- public static function send(string $emailId)
- {
- $email = Email::findOrFail($emailId);
-
- info("メール送信", [
- 'id' => $email->id,
- 'email' => $email->email,
- 'mailer' => $email->type,
- ]);
-
- try {
- Mail::to($email->email)
- ->send(new TextEmail($email->subject, $email->content, $email->emailAttachments));
- } catch (Exception $e) {
- Log::error("メール送信失敗", [
- 'id' => $email->id,
- 'email' => $email->email,
- 'mailer' => $email->type,
- ]);
- $email->is_failed = true;
- $email->save();
- throw $e;
- }
-
-
- $email->send_datetime = DateUtil::now();
- $email->save();
- }
- }
|