Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
5f92cccad6
@ -400,6 +400,7 @@ $routes->get("driveListFiles", "GoogleDriveController::listFiles");
|
||||
$routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
||||
$routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
|
||||
$routes->get('downloadGdriveFile', 'GoogleDriveController::downloadGdriveFile', ['filter' => 'authMVC']);
|
||||
$routes->get('cli/sendZeptoMail', 'MasterController::testZeptoSMTP');
|
||||
|
||||
$routes->cli('cli/processjob', 'JobWorker::processJob');
|
||||
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
|
||||
@ -407,6 +408,7 @@ $routes->cli('cli/processjobs', 'JobWorker::processJobs');
|
||||
$routes->get("processjob", "JobWorker::processJob");
|
||||
$routes->cli('cli/new_gmail_token', 'MasterController::generateNewGmailAPIToken');
|
||||
$routes->cli('cli/send_mail_cli', 'MasterController::testGmailAPIViaCLI');
|
||||
$routes->cli('cli/sendZeptoMail', 'MasterController::testZeptoSMTP');
|
||||
$routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMails');
|
||||
$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
|
||||
$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
|
||||
|
||||
@ -344,6 +344,15 @@ class EmployeeServiceController extends AdminController
|
||||
'data_type' => 'str',
|
||||
'format' => null,
|
||||
'allowed_values' => null
|
||||
],
|
||||
'claim_status' => [
|
||||
'col_idx' => 6,
|
||||
'col_cell_name' => 'G',
|
||||
'col_name' => 'Claim status',
|
||||
'is_mandatory' => ['D'],
|
||||
'data_type' => 'str',
|
||||
'format' => null,
|
||||
'allowed_values' => [0,1]
|
||||
]
|
||||
];
|
||||
|
||||
@ -1334,6 +1343,7 @@ class EmployeeServiceController extends AdminController
|
||||
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => $row[4],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'inactive','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'claim_status','old_value' => $data['claim_status'],'new_value' => $row[6],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id'],'status' => 'pending']);
|
||||
};
|
||||
//iterate each row
|
||||
foreach ($excel_data as $col_key => $row)
|
||||
@ -1368,7 +1378,7 @@ class EmployeeServiceController extends AdminController
|
||||
if(!in_array($employee['id'],$endorsement_data))//make entry in endorsement firsttime only with checking that PK of emp exisintg in variable $endorsement_data
|
||||
{
|
||||
$employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first();
|
||||
$data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status']];
|
||||
$data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status'],'claim_status' => $employee_policy['claim_status']];
|
||||
$endorsement($data,$file,$row);
|
||||
$endorsement_data[] = $employee['id'];
|
||||
}
|
||||
|
||||
@ -1660,7 +1660,35 @@ class MasterController extends AdminController
|
||||
print_r($res);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testZeptoSMTP() {
|
||||
$message = '<style>body{font-family:Arial,sans-serif;color:#333;line-height:1.6;margin:0;padding:0}.email-container{width:100%;max-width:600px;margin:0 auto;padding:20px;border:1px solid #e0e0e0;background-color:#f9f9f9}.header{background-color:#4a90e2;color:#fff;padding:15px;text-align:center}.header h1{margin:0;font-size:24px}.content{padding:20px;background-color:#fff}.content h2{color:#4a90e2;font-size:20px;margin-top:0}.content p{margin:10px 0}.details-table{width:100%;border-collapse:collapse;margin-top:20px}.details-table td,.details-table th{border:1px solid #ddd;padding:10px;text-align:left}.details-table th{background-color:#f2f2f2}.footer{margin-top:20px;font-size:12px;color:#777;text-align:center}.attachment-note{margin-top:20px;padding:10px;background-color:#f7f7f7;border-left:4px solid #4a90e2;font-style:italic}</style><div class=email-container><div class=header><h1>Request for Quotation (RFQ)</h1></div><div class=content><h2>Dear {{RECIPIENT_NAME}},</h2><p>We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.<h2>RFQ Details</h2><table class=details-table><tr><th>Client name<td>{{CLIENT_NAME}}<tr><th>Coverage Type<td>{{POLICY_LONG_NAME}}<tr><th>Policy Start Date<td>{{POLICY_START_DATE}}<tr><th>Policy Duration<td>{{DURATION}}</table><div class=attachment-note>Please note: Additional terms and details are included in the attachment for your reference.</div><p>Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.<p>Best regards,<p><strong>Nhance India Pvt Ltd</strong><br></div><div class=footer><p>© Nhance India Pvt Ltd. All rights reserved.</div></div>';
|
||||
$attachments = [
|
||||
["filePath" => ROOTPATH."public/sample_excel/sample_addition.xls","fileName" => "sample_addition.xls"],
|
||||
["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
|
||||
["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
|
||||
];
|
||||
$email_id = 'srinivas.saravanan@venbainfotech.com';
|
||||
$common = ['mail_type'=>'test_mail_cli'];
|
||||
// Send email and get response
|
||||
$result = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]);
|
||||
|
||||
|
||||
log_message('error',json_encode($result));
|
||||
// Format the response for display/debugging
|
||||
$response = [
|
||||
'success' => $result['success'] ?? false,
|
||||
'smtp_data' => [
|
||||
'last_reply' => $result['smtp_data']['last_reply'] ?? '',
|
||||
'error_info' => $result['smtp_data']['error_info'] ?? ''
|
||||
],
|
||||
'message_id' => $result['message_id'] ?? '',
|
||||
'timestamp' => $result['timestamp'] ?? ''
|
||||
];
|
||||
|
||||
// Return JSON response
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
public function testCheckBounceMails()
|
||||
{
|
||||
$gmailapi = \Config\Services::gmailapi();
|
||||
|
||||
@ -119,9 +119,9 @@ class ExcelMergeHelper {
|
||||
$newName = $sheetName;
|
||||
$counter = 1;
|
||||
|
||||
while ($mergedSpreadsheet->sheetNameExists($newName)) {
|
||||
$newName = $sheetName . '_' . $counter++;
|
||||
log_message('debug', "Sheet name already exists. Generating new name: {$newName}");
|
||||
while (in_array($newName, $mergedSpreadsheet->getSheetNames())) {
|
||||
$newName = $sheetName . "_" . $counter++;
|
||||
log_message('debug', "Sheet name already exists. Trying new name: {$newName}");
|
||||
}
|
||||
|
||||
// Clone the worksheet and set the new name
|
||||
|
||||
@ -77,17 +77,16 @@ class GmailResponseHandler{
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == 1 ){
|
||||
$data['gmail_api_status'] = isset($params['gmail_api']['status']) ? $params['gmail_api']['status'] : null;
|
||||
$data['gmail_api_id'] = isset($params['gmail_api']['data']['id']) ? $params['gmail_api']['data']['id'] : null;
|
||||
$data['received_message'] = isset($params['gmail_api']['data']['labelIds']) ? json_encode($params['gmail_api']['data']['labelIds']) : null;
|
||||
if(isset($params['zepto_api']['data']) && $params['zepto_api']['message'] == 'OK' ){
|
||||
$data['gmail_api_status'] = isset($params['zepto_api']['data']) ? $params['zepto_api']['data'][0]['code'] : null;
|
||||
$data['gmail_api_id'] = isset($params['zepto_api']['request_id']) ? $params['zepto_api']['request_id'] : null;
|
||||
$data['received_message'] = isset($params['zepto_api']['data'][0]['message']) ? json_encode($params['zepto_api']['data'][0]['message']) : null;
|
||||
|
||||
}
|
||||
elseif(isset($params['gmail_api']['status']) && $params['gmail_api']['status'] == false ){
|
||||
$data['gmail_api_status'] = $params['gmail_api']['status'];
|
||||
if(isset($params['gmail_api']['data'])){
|
||||
$data['received_message'] = json_encode($params['gmail_api']['data']);
|
||||
}
|
||||
elseif(isset($params['zepto_api']['error'])){
|
||||
$data['gmail_api_status'] = isset($params['zepto_api']['error']['code'])?$params['zepto_api']['error']['code']:null;
|
||||
$data['received_message'] = json_encode($params['zepto_api']);
|
||||
$data['gmail_api_id'] = isset($params['zepto_api']['error']['request_id']) ? $params['zepto_api']['error']['request_id'] : null;
|
||||
}
|
||||
|
||||
$gmailModel = new GmailSentHistoryModel();
|
||||
@ -96,7 +95,9 @@ class GmailResponseHandler{
|
||||
|
||||
public function gmail_response_logger($params)
|
||||
{
|
||||
$this->myLogger->logme('error',json_encode($params));
|
||||
if(isset($params['zepto_api']['error'])){
|
||||
$this->myLogger->logme('error',json_encode($params));
|
||||
}
|
||||
}
|
||||
|
||||
public function client_id_flag_setter($params)
|
||||
@ -119,7 +120,6 @@ class GmailResponseHandler{
|
||||
$error = $e->getMessage();
|
||||
$this->myLogger->logme('error','An Error Occured - '.$error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,177 +1,422 @@
|
||||
<?php
|
||||
|
||||
// namespace App\Helpers;
|
||||
// use Psr\Log\LoggerInterface;
|
||||
|
||||
// use App\Controllers\BaseController;
|
||||
|
||||
// use PHPMailer\PHPMailer\PHPMailer;
|
||||
// use PHPMailer\PHPMailer\SMTP;
|
||||
// use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// use App\Models\JobModel;
|
||||
|
||||
// class MailHelper
|
||||
// {
|
||||
// public static function send_email_smtp($params)
|
||||
// {
|
||||
|
||||
// // print_r($params);die;
|
||||
// $myLogger = \Config\Services::mylogger();
|
||||
// $emaill = $params['mail'];
|
||||
// $subject = $params['subject'];
|
||||
// $message = $params['message'];
|
||||
// if (isset($params['bcc'])) {
|
||||
// $bcc = $params['bcc'];
|
||||
// }else{
|
||||
// $bcc= '';
|
||||
// }
|
||||
// try {
|
||||
|
||||
// $email = \Config\Services::email();
|
||||
// $email->setMailType('html');
|
||||
// $email->setFrom('bbone@venbait.in', 'Nhance');
|
||||
|
||||
// $email->setTo($emaill);
|
||||
|
||||
// if (!empty($bcc)) {
|
||||
// // Convert the comma-separated string into an array
|
||||
// $bccList = explode(',', $bcc);
|
||||
// // Trim whitespace from each email ID
|
||||
// $bccList = array_map('trim', $bccList);
|
||||
// // Set BCC recipients
|
||||
// $email->setBCC($bccList);
|
||||
// }
|
||||
|
||||
// $email->setSubject($subject);
|
||||
|
||||
// $email->setMessage($message);
|
||||
|
||||
// if ($email->send()) {
|
||||
|
||||
// return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $emaill,],200);
|
||||
// } else {
|
||||
// $myLogger->logme('error', "mail sent failed - $emaill");
|
||||
// return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $emaill ],404);
|
||||
// }
|
||||
|
||||
// } catch (Exception $e) {
|
||||
// $msg = $e->getMessage();
|
||||
// $myLogger->logme('error', "mail sent failed - $msg");
|
||||
// return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public static function bulk_mail_smtp(array $mails = [])
|
||||
// {
|
||||
// // print_r();die;
|
||||
// $model = new JobModel();
|
||||
// $start = microtime(true);
|
||||
// $runtime= 0;
|
||||
// try {
|
||||
// foreach ( $mails as $index=>$mail) {
|
||||
// $runtime = microtime(true) - $start;
|
||||
// $send_mail = self::send_email($mail);
|
||||
// }
|
||||
|
||||
// return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
|
||||
|
||||
// } catch (\Throwable $th) {
|
||||
// return json_encode(['status' => 'failed','code' => 500],500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //using GmailAPI
|
||||
// public static function send_email($params)
|
||||
// {
|
||||
|
||||
// // print_r($params);die;
|
||||
// $myLogger = \Config\Services::mylogger();
|
||||
// $gmailapi = \Config\Services::gmailapi();
|
||||
|
||||
// $emaill = $params['mail'];
|
||||
// $subject = $params['subject'];
|
||||
// $message = $params['message'];
|
||||
// $attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : [];
|
||||
// $common = isset($params['common'])?$params['common']:'';
|
||||
// //check BCC mail
|
||||
// if (isset($params['bcc'])) {
|
||||
// $bcc = $params['bcc'];
|
||||
// if(!is_array($bcc)){
|
||||
// $bcc = explode(',', $bcc);
|
||||
// }
|
||||
// }else{
|
||||
// $bcc = [];
|
||||
// }
|
||||
|
||||
// //check CC mail
|
||||
// if (isset($params['cc'])) {
|
||||
// $cc = $params['cc'];
|
||||
// if(!is_array($cc)){
|
||||
// $cc = explode(',', $cc);
|
||||
// }
|
||||
// }else{
|
||||
// $cc = [];
|
||||
// }
|
||||
|
||||
// //check REPLY TO mail
|
||||
// $reply_to = "";
|
||||
// if(isset($params['reply_to']) && !empty($params['reply_to'])){
|
||||
// $reply_to = $params['reply_to'];
|
||||
// }
|
||||
// $MailDataHelper = new GmailResponseHandler();
|
||||
|
||||
// $res['params'] = $params;
|
||||
// try {
|
||||
|
||||
// $res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments);
|
||||
// if($res['gmail_api']['status'])
|
||||
// {
|
||||
// $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);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $myLogger->logme('error', "mail sent failed - $emaill");
|
||||
// $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);
|
||||
// }
|
||||
|
||||
// } catch (Exception $e) {
|
||||
// $msg['error'] = $e->getMessage();
|
||||
// $msg['params'] = $params;
|
||||
// $myLogger->logme('error', "mail sent failed - $msg");
|
||||
// $response = $msg;
|
||||
// $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 = [])
|
||||
// {
|
||||
// // print_r($mails);die;
|
||||
// $model = new JobModel();
|
||||
// $start = microtime(true);
|
||||
// $runtime= 0;
|
||||
// try {
|
||||
// foreach ( $mails as $index=>$mail) {
|
||||
// $runtime = microtime(true) - $start;
|
||||
// $send_mail = self::send_email($mail);
|
||||
// }
|
||||
|
||||
// return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
|
||||
|
||||
// } catch (\Throwable $th) {
|
||||
// $error = $th->getMessage();
|
||||
// log_message('error',$error);
|
||||
// return json_encode(['status' => 'failed','code' => 500,'error'=>$error],500);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
namespace App\Helpers;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
use App\Models\JobModel;
|
||||
|
||||
class MailHelper
|
||||
{
|
||||
public static function send_email_smtp($params)
|
||||
{
|
||||
|
||||
// print_r($params);die;
|
||||
$myLogger = \Config\Services::mylogger();
|
||||
$emaill = $params['mail'];
|
||||
$subject = $params['subject'];
|
||||
$message = $params['message'];
|
||||
if (isset($params['bcc'])) {
|
||||
$bcc = $params['bcc'];
|
||||
}else{
|
||||
$bcc= '';
|
||||
} else {
|
||||
$bcc = '';
|
||||
}
|
||||
$from_address = getenv('email.fromEmail');
|
||||
|
||||
|
||||
try {
|
||||
|
||||
$email = \Config\Services::email();
|
||||
$email->setMailType('html');
|
||||
$email->setFrom('bbone@venbait.in', 'Nhance');
|
||||
|
||||
$email->setTo($emaill);
|
||||
$curl = curl_init();
|
||||
$postData = [
|
||||
'from' => [
|
||||
'address' => $from_address
|
||||
],
|
||||
'to' => [
|
||||
[
|
||||
'email_address' => [
|
||||
'address' => $emaill
|
||||
]
|
||||
]
|
||||
],
|
||||
'subject' => $subject,
|
||||
'htmlbody' => $message
|
||||
];
|
||||
|
||||
// Add BCC if present
|
||||
if (!empty($bcc)) {
|
||||
// Convert the comma-separated string into an array
|
||||
$bccList = explode(',', $bcc);
|
||||
// Trim whitespace from each email ID
|
||||
$bccList = array_map('trim', $bccList);
|
||||
// Set BCC recipients
|
||||
$email->setBCC($bccList);
|
||||
$postData['bcc'] = array_map(function($email) {
|
||||
return [
|
||||
'email_address' => [
|
||||
'address' => $email
|
||||
]
|
||||
];
|
||||
}, $bccList);
|
||||
}
|
||||
|
||||
$email->setSubject($subject);
|
||||
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",
|
||||
],
|
||||
]);
|
||||
|
||||
$email->setMessage($message);
|
||||
$response = curl_exec($curl);
|
||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($curl);
|
||||
|
||||
if ($email->send()) {
|
||||
curl_close($curl);
|
||||
if ($err) {
|
||||
$myLogger->logme('error', "mail sent failed - $emaill");
|
||||
return json_encode(['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $emaill], 404);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $emaill,],200);
|
||||
$apiResponse = json_decode($response, true);
|
||||
|
||||
if ($httpCode === 200) {
|
||||
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $emaill], 200);
|
||||
} else {
|
||||
$myLogger->logme('error', "mail sent failed - $emaill");
|
||||
return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $emaill ],404);
|
||||
return json_encode(['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $emaill], 404);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
$myLogger->logme('error', "mail sent failed - $msg");
|
||||
return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
|
||||
}
|
||||
return json_encode(['status' => 'failed', 'code' => 500, 'data' => $emaill], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public static function bulk_mail_smtp(array $mails = [])
|
||||
{
|
||||
// print_r();die;
|
||||
$model = new JobModel();
|
||||
$start = microtime(true);
|
||||
$runtime= 0;
|
||||
try {
|
||||
foreach ( $mails as $index=>$mail) {
|
||||
$runtime = 0;
|
||||
try {
|
||||
foreach ($mails as $index => $mail) {
|
||||
$runtime = microtime(true) - $start;
|
||||
$send_mail = self::send_email($mail);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...'], 200);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return json_encode(['status' => 'failed','code' => 500],500);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
return json_encode(['status' => 'failed', 'code' => 500], 500);
|
||||
}
|
||||
}
|
||||
|
||||
//using GmailAPI
|
||||
public static function send_email($params)
|
||||
public static function send_email($params)
|
||||
{
|
||||
|
||||
// print_r($params);die;
|
||||
$myLogger = \Config\Services::mylogger();
|
||||
$gmailapi = \Config\Services::gmailapi();
|
||||
|
||||
|
||||
$emaill = $params['mail'];
|
||||
$subject = $params['subject'];
|
||||
$message = $params['message'];
|
||||
$attachments = isset($params['attachments']) && count($params['attachments']) ? $params['attachments'] : [];
|
||||
$common = isset($params['common'])?$params['common']:'';
|
||||
//check BCC mail
|
||||
if (isset($params['bcc'])) {
|
||||
$bcc = $params['bcc'];
|
||||
if(!is_array($bcc)){
|
||||
$bcc = explode(',', $bcc);
|
||||
}
|
||||
}else{
|
||||
$bcc = [];
|
||||
}
|
||||
$attachments = isset($params['attachments']) ? $params['attachments'] : [];
|
||||
$common = isset($params['common']) ? $params['common'] : '';
|
||||
|
||||
//check CC mail
|
||||
if (isset($params['cc'])) {
|
||||
$cc = $params['cc'];
|
||||
if(!is_array($cc)){
|
||||
$cc = explode(',', $cc);
|
||||
}
|
||||
}else{
|
||||
$cc = [];
|
||||
}
|
||||
|
||||
//check REPLY TO mail
|
||||
$reply_to = "";
|
||||
if(isset($params['reply_to']) && !empty($params['reply_to'])){
|
||||
$reply_to = $params['reply_to'];
|
||||
}
|
||||
$MailDataHelper = new GmailResponseHandler();
|
||||
|
||||
$res['params'] = $params;
|
||||
$from_address = getenv('email.fromEmail');
|
||||
try {
|
||||
|
||||
$res['gmail_api'] = $gmailapi->sendMessage($emaill, $subject, $message, 'no-reply@nhanceindia.in', $reply_to, $cc, $bcc,$attachments);
|
||||
if($res['gmail_api']['status'])
|
||||
{
|
||||
$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);
|
||||
}
|
||||
else
|
||||
{
|
||||
$myLogger->logme('error', "mail sent failed - $emaill");
|
||||
$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);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$curl = curl_init();
|
||||
|
||||
$postData = [
|
||||
'from' => [
|
||||
'address' => $from_address
|
||||
],
|
||||
'to' => [
|
||||
[
|
||||
'email_address' => [
|
||||
'address' => $emaill
|
||||
]
|
||||
]
|
||||
],
|
||||
'subject' => $subject,
|
||||
'htmlbody' => $message
|
||||
];
|
||||
|
||||
// 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, // Add mime_type field
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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",
|
||||
],
|
||||
]);
|
||||
|
||||
$mail_result = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
// log_message('error','inside mail helper');
|
||||
// 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);
|
||||
|
||||
// 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;
|
||||
$myLogger->logme('error', "mail sent failed - $msg");
|
||||
$response = $msg;
|
||||
$response = $res;
|
||||
$MailDataHelper->receive_and_distribute_param_to_functions($response);
|
||||
return json_encode(['status' => 'failed','code' => 500,'data' => $msg],500);
|
||||
return json_encode([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'data' => $msg
|
||||
], 500);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function bulk_mail(array $mails = [])
|
||||
{
|
||||
// print_r($mails);die;
|
||||
$model = new JobModel();
|
||||
$start = microtime(true);
|
||||
$runtime= 0;
|
||||
try {
|
||||
foreach ( $mails as $index=>$mail) {
|
||||
$runtime = 0;
|
||||
try {
|
||||
foreach ($mails as $index => $mail) {
|
||||
$runtime = microtime(true) - $start;
|
||||
$send_mail = self::send_email($mail);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...'], 200);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$error = $th->getMessage();
|
||||
log_message('error', $error);
|
||||
return json_encode(['status' => 'failed', 'code' => 500, 'error' => $error], 500);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$error = $th->getMessage();
|
||||
log_message('error',$error);
|
||||
return json_encode(['status' => 'failed','code' => 500,'error'=>$error],500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -17,15 +17,15 @@
|
||||
"dompdf/dompdf": "^2.0",
|
||||
"firebase/php-jwt": "^6.10",
|
||||
"google/apiclient": "^2.15.0",
|
||||
"kreait/firebase-php": "^7.0",
|
||||
"laminas/laminas-escaper": "^2.9",
|
||||
"php-amqplib/php-amqplib": "^2.8",
|
||||
"phpmailer/phpmailer": "^6.9",
|
||||
"phpoffice/phpspreadsheet": "^2.1",
|
||||
"psr/http-message": "^1.0",
|
||||
"psr/log": "^1.1",
|
||||
"slim/slim": "^4.13",
|
||||
"zircote/swagger-php": "^4.8",
|
||||
"psr/http-message": "^1.0",
|
||||
"kreait/firebase-php":"^7.0"
|
||||
"zircote/swagger-php": "^4.8"
|
||||
},
|
||||
"require-dev": {
|
||||
"codeigniter/coding-standard": "^1.7",
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user