FIX_Mail Fixes

This commit is contained in:
venba-Inspriron-3558 2025-11-19 18:39:10 +05:30
parent 723a532212
commit 1c75413b64
3 changed files with 64 additions and 35 deletions

View File

@ -258,7 +258,7 @@ class NotificationController extends AdminController
$template_id = $this->request->getPost('template_id'); $template_id = $this->request->getPost('template_id');
$test_mail = $this->request->getPost('test_mail'); // $test_mail = $this->request->getPost('test_mail');
$test_mail_list = $this->request->getPost('test_mail_list'); $test_mail_list = $this->request->getPost('test_mail_list');
@ -268,27 +268,67 @@ class NotificationController extends AdminController
if(!empty($notification_data)){ if(!empty($notification_data)){
$params = [ // First Index as test mail all are testmaillist
'client_data' => $client_data, // $params = [
'notification_data' => $notification_data, // 'client_data' => $client_data,
'test_mail' => $test_mail, // 'notification_data' => $notification_data,
'test_mail_list' => $test_mail_list // 'test_mail' => $test_mail,
]; // 'test_mail_list' => $test_mail_list
// ];
// $testMailData = sendMailNotification::sendMailNotificationForTesting($notification_data['template_name'], $params);
// if (!empty($testMailData)) {
// $mail_send_return1 = MailHelper::send_email($testMailData);
// $this->myLogger->logme("info", $mail_send_return1);
// $this->myLogger->logme("info", $mail_send_return1);
// return $this->respond(['status' => true,'code' => 200, 'respond' => json_decode($mail_send_return1)]);
// }else{
// return $this->respond(['status' => false,'code' => 200, 'message' => 'Test Mail Data Does Not Exist']);
// }
$testMailData = sendMailNotification::sendMailNotificationForTesting($notification_data['template_name'], $params);
// print_r($testMailData); die;
if (!empty($testMailData)) {
$mail_send_return1 = MailHelper::send_email($testMailData); $mailArray = explode(',', $test_mail_list);
$this->myLogger->logme("info", $mail_send_return1); $successMails = [];
$this->myLogger->logme("info", $mail_send_return1); $failedMails = [];
return $this->respond(['status' => true,'code' => 200, 'respond' => json_decode($mail_send_return1)]); foreach ($mailArray as $singleMail) {
$singleMail = trim($singleMail);
}else{ $params = [
'client_data' => $client_data,
'notification_data' => $notification_data,
'test_mail' => $singleMail,
'test_mail_list' => "" // optional
];
$testMailData = sendMailNotification::sendMailNotificationForTesting($notification_data['template_name'], $params);
if (!empty($testMailData)) {
$mail_send_return1 = MailHelper::send_email($testMailData);
if ($mail_send_return1) {
$successMails[] = $singleMail;
} else {
$failedMails[] = $singleMail;
}
$this->myLogger->logme("info", "Mail attempt to {$singleMail}: " . $mail_send_return1);
} else {
$failedMails[] = $singleMail;
$this->myLogger->logme("info", "Test Mail Data Does Not Exist for {$singleMail}");
}
}
// Prepare final response
if (!empty($successMails)) {
$responseMessage = "Count " . count($successMails) . " mail(s) sent successfully: \n" . implode("\n", $successMails);
if (!empty($failedMails)) {
$responseMessage .= "\nCount " . count($failedMails) . " mail(s) failed: \n" . implode("\n", $failedMails);
}
return $this->respond(['status' => true,'code' => 200,'message' => $responseMessage]);
} else {
return $this->respond(['status' => false,'code' => 200,'message' => 'All mails failed to send: ' . implode(", ", $failedMails)]);
}
return $this->respond(['status' => false,'code' => 200, 'message' => 'Test Mail Data Does Not Exist']);
}
}else{ }else{
return $this->respond(['status' => false,'code' => 200, 'message' => 'Notification Template not enabled']); return $this->respond(['status' => false,'code' => 200, 'message' => 'Notification Template not enabled']);

View File

@ -318,7 +318,7 @@ class MailHelper
$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'] : ''; $bcc = isset($params['bcc']) ? $params['bcc'] : '';
$cc = isset($params['cc']) ? $params['cc'] : ''; $cc = (isset($params['cc']) && !empty($params['cc'])) ? $params['cc'] : '';
$from_address = isset($params['from_mail']) && !empty($params['from_mail']) ? $params['from_mail'] : getenv('email.fromEmail'); $from_address = isset($params['from_mail']) && !empty($params['from_mail']) ? $params['from_mail'] : getenv('email.fromEmail');
// $from_address = "claims@nhanceindia.in"; // $from_address = "claims@nhanceindia.in";

View File

@ -1368,7 +1368,7 @@
let test_mail_list = $('#common_mail').val(); let test_mail_list = $('#common_mail').val();
let test_mail = test_mail_list.split(',')[0] ?? ''; let test_mail = test_mail_list.split(',')[0] ?? ''; //REF:SVM
if (test_mail !== null || test_mail !== "") { if (test_mail !== null || test_mail !== "") {
@ -1400,30 +1400,19 @@
type: "POST", type: "POST",
data:{ data:{
template_id, template_id,
test_mail, test_mail_list,
test_mail_list
}, },
dataType: 'json', dataType: 'json',
success: function(res) { success: function(res) {
console.log('Test mail send function response', res);
console.log('Test mail send function response', res)
$('.loader').fadeOut(); $('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow'); $('.loader-mask').delay(350).fadeOut('slow');
if (res.status == true) { if (res.status === true) {
toastr.success(res.message, 'SUCCESS');
let respond = res.respond;
console.log('Parsed respond', respond)
if (respond.status == 'success') {
toastr.success(respond.message, 'SUCCESS')
} else {
toastr.warning(respond.message, 'WARNING')
}
} else { } else {
toastr.warning('Failed to sent mail', 'WARNING') toastr.warning('Failed to send mail', 'WARNING');
} }
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {