Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| EmailService | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| send | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Services\Email; |
| 4 | |
| 5 | use Illuminate\Support\Facades\Mail; |
| 6 | use Illuminate\Mail\Mailable; |
| 7 | use Illuminate\Support\Facades\Log; |
| 8 | |
| 9 | class EmailService |
| 10 | { |
| 11 | public function send( |
| 12 | string $to, |
| 13 | Mailable $mailable, |
| 14 | string $email_type, |
| 15 | ?bool $async = true, |
| 16 | ?string $bcc = null, |
| 17 | ?bool $disable_bcc = false |
| 18 | ): void { |
| 19 | try { |
| 20 | $mail = Mail::to($to); |
| 21 | |
| 22 | if (!$disable_bcc) { |
| 23 | $mail->bcc(config('hubspotconfig.bcc_email')); |
| 24 | } |
| 25 | |
| 26 | if ($bcc) { |
| 27 | $mail->bcc($bcc); |
| 28 | } |
| 29 | |
| 30 | if ($async) { |
| 31 | $mail->queue($mailable); |
| 32 | } else { |
| 33 | $mail->send($mailable); |
| 34 | } |
| 35 | |
| 36 | Log::info('Email Action Log', [ |
| 37 | 'tag' => 'Email', |
| 38 | 'email_type' => $email_type, |
| 39 | 'recipient_email' => $to, |
| 40 | 'is_queue' => $async, |
| 41 | 'bcc_email' => $bcc |
| 42 | ]); |
| 43 | } catch (\Exception $e) { |
| 44 | Log::error('Error sending email:', [ |
| 45 | 'tag' => 'Email', |
| 46 | 'email_type' => $email_type, |
| 47 | 'recipient_email' => $to, |
| 48 | 'is_queue' => $async, |
| 49 | 'bcc_email' => $bcc, |
| 50 | 'error_message' => $e->getMessage() |
| 51 | ]); |
| 52 | } |
| 53 | } |
| 54 | } |