Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
public_html
/
admin_new2
/
app
/
Services
/
Filename :
EmailService.php
back
Copy
<?php namespace App\Services; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Log; class EmailService { public function sendEmail($toAddress, $toName, $subject, $htmlBody, $toAddresses = [], $ccAddresses = [], $bccAddresses = []) { $curl = curl_init(); // Prepare recipient data $toRecipients = []; $ccRecipients = []; $bccRecipients = []; if(!empty($toAddresses)){ $toRecipients = array_map(function ($recipient) { return ['email_address' => ['address' => $recipient['email'], 'name' => $recipient['name']]]; }, $toAddresses); } if(!empty($ccAddresses)){ $ccRecipients = array_map(function ($recipient) { return ['email_address' => ['address' => $recipient['email'], 'name' => $recipient['name']]]; }, $ccAddresses); } if(!empty($bccAddresses)){ $bccRecipients = array_map(function ($recipient) { return ['email_address' => ['address' => $recipient['email'], 'name' => $recipient['name']]]; }, $bccAddresses); } if(empty($toRecipients)){ $toRecipients[] = ['email_address' => ['address' => $toAddress, 'name' => $toName]]; } $emailData = [ 'from' => ['address' => Config::get('constants.app.from-email')], 'to' => $toRecipients, 'cc' => $ccRecipients, 'bcc' => $bccRecipients, 'subject' => $subject, 'htmlbody' => $htmlBody, ]; $email_token = Config::get('constants.app.send-mail-token'); $curlOptions = [ CURLOPT_URL => "https://api.zeptomail.com/v1.1/email", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode($emailData), CURLOPT_HTTPHEADER => [ "accept: application/json", "authorization:Zoho-enczapikey " . $email_token, "cache-control: no-cache", "content-type: application/json", ], ]; Log::debug("Token:" . var_export($curlOptions, true)); curl_setopt_array($curl, $curlOptions); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { return ['success' => false, 'message' => "cURL Error #:" . $err]; } else { $decodedResponse = json_decode($response, true); if (isset($decodedResponse['error'])) { return ['success' => false, 'message' => var_export($decodedResponse['error'], true)]; } else { return ['success' => true, 'message' => $response]; } } } } ?>