FIX_ZEPT_BCC_CC_SRINIVAS
This commit is contained in:
parent
68874796fd
commit
9ff631ee16
@ -255,7 +255,7 @@ class MailHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
$apiResponse = json_decode($response, true);
|
$apiResponse = json_decode($response, true);
|
||||||
|
log_message('error',$apiResponse);
|
||||||
if ($httpCode === 200) {
|
if ($httpCode === 200) {
|
||||||
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $emaill], 200);
|
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $emaill], 200);
|
||||||
} else {
|
} else {
|
||||||
@ -289,116 +289,141 @@ class MailHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function send_email($params)
|
public static function send_email($params)
|
||||||
{
|
{
|
||||||
$myLogger = \Config\Services::mylogger();
|
$myLogger = \Config\Services::mylogger();
|
||||||
|
|
||||||
$emaill = $params['mail'];
|
$emaill = $params['mail'];
|
||||||
$subject = $params['subject'];
|
$subject = $params['subject'];
|
||||||
$message = $params['message'];
|
$message = $params['message'];
|
||||||
$attachments = isset($params['attachments']) ? $params['attachments'] : [];
|
$attachments = isset($params['attachments']) ? $params['attachments'] : [];
|
||||||
$common = isset($params['common']) ? $params['common'] : '';
|
$common = isset($params['common']) ? $params['common'] : '';
|
||||||
|
$bcc = isset($params['bcc']) ? $params['bcc'] : '';
|
||||||
|
$cc = isset($params['cc']) ? $params['cc'] : '';
|
||||||
|
|
||||||
$from_address = getenv('email.fromEmail');
|
$from_address = getenv('email.fromEmail');
|
||||||
try {
|
try {
|
||||||
$curl = curl_init();
|
$curl = curl_init();
|
||||||
|
|
||||||
$postData = [
|
$postData = [
|
||||||
'from' => [
|
'from' => [
|
||||||
'address' => $from_address
|
'address' => $from_address
|
||||||
],
|
],
|
||||||
'to' => [
|
'to' => [
|
||||||
[
|
[
|
||||||
'email_address' => [
|
'email_address' => [
|
||||||
'address' => $emaill
|
'address' => $emaill
|
||||||
]
|
|
||||||
]
|
]
|
||||||
],
|
]
|
||||||
'subject' => $subject,
|
],
|
||||||
'htmlbody' => $message
|
'subject' => $subject,
|
||||||
];
|
'htmlbody' => $message
|
||||||
|
];
|
||||||
|
|
||||||
// Handle attachments
|
// Add CC recipients if provided
|
||||||
if (!empty($attachments)) {
|
if (!empty($cc)) {
|
||||||
$postData['attachments'] = [];
|
$postData['cc'] = [];
|
||||||
foreach ($attachments as $attachment) {
|
// Handle both string and array inputs for CC
|
||||||
if (isset($attachment['filePath']) && file_exists($attachment['filePath'])) {
|
$ccEmails = is_array($cc) ? $cc : [$cc];
|
||||||
// Determine MIME type dynamically
|
foreach ($ccEmails as $ccEmail) {
|
||||||
$fileMimeType = mime_content_type($attachment['filePath']);
|
$postData['cc'][] = [
|
||||||
|
'email_address' => [
|
||||||
|
'address' => $ccEmail
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$postData['attachments'][] = [
|
// Add BCC recipients if provided
|
||||||
'content' => base64_encode(file_get_contents($attachment['filePath'])),
|
if (!empty($bcc)) {
|
||||||
'name' => $attachment['fileName'],
|
$postData['bcc'] = [];
|
||||||
'mime_type' => $fileMimeType, // Add mime_type field
|
// Handle both string and array inputs for BCC
|
||||||
];
|
$bccEmails = is_array($bcc) ? $bcc : [$bcc];
|
||||||
}
|
foreach ($bccEmails as $bccEmail) {
|
||||||
|
$postData['bcc'][] = [
|
||||||
|
'email_address' => [
|
||||||
|
'address' => $bccEmail
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle attachments
|
||||||
|
if (!empty($attachments)) {
|
||||||
|
$postData['attachments'] = [];
|
||||||
|
foreach ($attachments as $attachment) {
|
||||||
|
if (isset($attachment['filePath']) && file_exists($attachment['filePath'])) {
|
||||||
|
// Determine MIME type dynamically
|
||||||
|
$fileMimeType = mime_content_type($attachment['filePath']);
|
||||||
|
|
||||||
|
$postData['attachments'][] = [
|
||||||
|
'content' => base64_encode(file_get_contents($attachment['filePath'])),
|
||||||
|
'name' => $attachment['fileName'],
|
||||||
|
'mime_type' => $fileMimeType,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_setopt_array($curl, [
|
||||||
|
CURLOPT_URL => "https://api.zeptomail.in/v1.1/email",
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_ENCODING => "",
|
||||||
|
CURLOPT_MAXREDIRS => 10,
|
||||||
|
CURLOPT_TIMEOUT => 30,
|
||||||
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||||
|
CURLOPT_CUSTOMREQUEST => "POST",
|
||||||
|
CURLOPT_POSTFIELDS => json_encode($postData),
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"accept: application/json",
|
||||||
|
"authorization: Zoho-enczapikey " . getenv('ZEPTO_API_KEY'),
|
||||||
|
"cache-control: no-cache",
|
||||||
|
"content-type: application/json",
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
curl_setopt_array($curl, [
|
$mail_result = curl_exec($curl);
|
||||||
CURLOPT_URL => "https://api.zeptomail.in/v1.1/email",
|
$err = curl_error($curl);
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
curl_close($curl);
|
||||||
CURLOPT_ENCODING => "",
|
|
||||||
CURLOPT_MAXREDIRS => 10,
|
|
||||||
CURLOPT_TIMEOUT => 30,
|
|
||||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
||||||
CURLOPT_CUSTOMREQUEST => "POST",
|
|
||||||
CURLOPT_POSTFIELDS => json_encode($postData),
|
|
||||||
CURLOPT_HTTPHEADER => [
|
|
||||||
"accept: application/json",
|
|
||||||
"authorization: Zoho-enczapikey " . getenv('ZEPTO_API_KEY'),
|
|
||||||
"cache-control: no-cache",
|
|
||||||
"content-type: application/json",
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$mail_result = curl_exec($curl);
|
$res['params'] = $params;
|
||||||
$err = curl_error($curl);
|
$MailDataHelper = new GmailResponseHandler();
|
||||||
curl_close($curl);
|
$apiResponse = json_decode($mail_result, true);
|
||||||
// log_message('error','inside mail helper');
|
$res['zepto_api'] = $apiResponse;
|
||||||
// log_message('error', $response.' error->'.$err);die();
|
|
||||||
$res['params'] = $params;
|
|
||||||
$MailDataHelper = new GmailResponseHandler();
|
|
||||||
$apiResponse = json_decode($mail_result, true);
|
|
||||||
$res['zepto_api'] = $apiResponse;
|
|
||||||
if (isset($apiResponse['error'])) {
|
|
||||||
$response = $res;
|
|
||||||
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
|
||||||
return json_encode([
|
|
||||||
'status' => 'failed',
|
|
||||||
'code' => 404,
|
|
||||||
'message' => 'Email Sent Failed...' . $emaill,
|
|
||||||
'data' => $res
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
// $apiResponse = json_decode($response, true);
|
if (isset($apiResponse['error'])) {
|
||||||
|
|
||||||
// Check if request_id exists in response (indicates success)
|
|
||||||
if (isset($apiResponse['data'])) {
|
|
||||||
$response = $res;
|
|
||||||
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
|
||||||
return json_encode([
|
|
||||||
'status' => 'success',
|
|
||||||
'code' => 200,
|
|
||||||
'message' => 'Email Sent Successfully...' . $emaill,
|
|
||||||
'data' => $res
|
|
||||||
], 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$msg['error'] = $e->getMessage();
|
|
||||||
$msg['params'] = $params;
|
|
||||||
$response = $res;
|
$response = $res;
|
||||||
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
return json_encode([
|
return json_encode([
|
||||||
'status' => 'failed',
|
'status' => 'failed',
|
||||||
'code' => 500,
|
'code' => 404,
|
||||||
'data' => $msg
|
'message' => 'Email Sent Failed...' . $emaill,
|
||||||
], 500);
|
'data' => $res
|
||||||
|
], 404);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (isset($apiResponse['data'])) {
|
||||||
|
$response = $res;
|
||||||
|
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
|
return json_encode([
|
||||||
|
'status' => 'success',
|
||||||
|
'code' => 200,
|
||||||
|
'message' => 'Email Sent Successfully...' . $emaill,
|
||||||
|
'data' => $res
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$msg['error'] = $e->getMessage();
|
||||||
|
$msg['params'] = $params;
|
||||||
|
$response = $res;
|
||||||
|
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||||
|
return json_encode([
|
||||||
|
'status' => 'failed',
|
||||||
|
'code' => 500,
|
||||||
|
'data' => $msg
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static function bulk_mail(array $mails = [])
|
public static function bulk_mail(array $mails = [])
|
||||||
{
|
{
|
||||||
$model = new JobModel();
|
$model = new JobModel();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user