client = new Client(); $this->apiKey = env('BREVO_API_KEY'); $this->mailFromAddress = env('BREVO_MAIL_FROM_ADDRESS'); $this->mailFromName = env('BREVO_MAIL_FROM_NAME'); } public function expenseCreated($recipientEmail, $recipientName, ExpenseCreated $mail) { $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML try { $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'api-key' => $this->apiKey, 'content-type' => 'application/json', ], 'json' => [ 'sender' => [ 'name' => $this->mailFromName, 'email' => $this->mailFromAddress, ], 'to' => [ [ 'email' => $recipientEmail, 'name' => $recipientName, ], ], 'subject' => 'Expense Created', 'htmlContent' => $htmlContent, ], 'verify' => false, ]); return json_decode($response->getBody(), true); } catch (RequestException $e) { Log::error('Brevo email failed to send', [ 'error' => $e->getMessage(), 'recipient' => $recipientEmail, ]); return null; } } public function expenseApproved($recipientEmail, $recipientName, ExpenseApproved $mail) { $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML try { $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'api-key' => $this->apiKey, 'content-type' => 'application/json', ], 'json' => [ 'sender' => [ 'name' => $this->mailFromName, 'email' => $this->mailFromAddress, ], 'to' => [ [ 'email' => $recipientEmail, 'name' => $recipientName, ], ], 'subject' => 'Expense First Approval', 'htmlContent' => $htmlContent, ], 'verify' => false, // Disable SSL verification ]); return json_decode($response->getBody(), true); } catch (RequestException $e) { Log::error('Brevo email failed to send', [ 'error' => $e->getMessage(), 'recipient' => $recipientEmail, ]); return null; } } public function expenseApproved2($recipientEmail, $recipientName, ExpenseApproved2 $mail) { $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML try { $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'api-key' => $this->apiKey, 'content-type' => 'application/json', ], 'json' => [ 'sender' => [ 'name' => $this->mailFromName, 'email' => $this->mailFromAddress, ], 'to' => [ [ 'email' => $recipientEmail, 'name' => $recipientName, ], ], 'subject' => 'Expense Second Approval', 'htmlContent' => $htmlContent, ], 'verify' => false, // Disable SSL verification ]); return json_decode($response->getBody(), true); } catch (RequestException $e) { Log::error('Brevo email failed to send', [ 'error' => $e->getMessage(), 'recipient' => $recipientEmail, ]); return null; } } public function expenseFinalApproved($recipientEmail, $recipientName, FinalApprove $mail) { $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML try { $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'api-key' => $this->apiKey, 'content-type' => 'application/json', ], 'json' => [ 'sender' => [ 'name' => $this->mailFromName, 'email' => $this->mailFromAddress, ], 'to' => [ [ 'email' => $recipientEmail, 'name' => $recipientName, ], ], 'subject' => 'Expense Final Approval', 'htmlContent' => $htmlContent, ], 'verify' => false, // Disable SSL verification ]); return json_decode($response->getBody(), true); } catch (RequestException $e) { Log::error('Brevo email failed to send', [ 'error' => $e->getMessage(), 'recipient' => $recipientEmail, ]); return null; } } public function expenseRejected($recipientEmail, $recipientName, ExpenseRejected $mail) { $htmlContent = $mail->renderHtml(); // Convert Blade view to HTML try { $response = $this->client->post('https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'api-key' => $this->apiKey, 'content-type' => 'application/json', ], 'json' => [ 'sender' => [ 'name' => $this->mailFromName, 'email' => $this->mailFromAddress, ], 'to' => [ [ 'email' => $recipientEmail, 'name' => $recipientName, ], ], 'subject' => 'Expense Rejected', 'htmlContent' => $htmlContent, ], 'verify' => false, // Disable SSL verification ]); return json_decode($response->getBody(), true); } catch (RequestException $e) { Log::error('Brevo email failed to send', [ 'error' => $e->getMessage(), 'recipient' => $recipientEmail, ]); return null; } } }