122 lines
4.8 KiB
PHP
122 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
class MailHelper
|
|
{
|
|
public static function send_otp_email($email_id, $otp)
|
|
{
|
|
|
|
$subject = 'BB-Sign Verify Document';
|
|
$message = "Hai,
|
|
<br>
|
|
We have a requested forgot password OTP: " . $otp;
|
|
|
|
try {
|
|
$email = \Config\Services::email();
|
|
|
|
// $email->initialize([
|
|
// 'protocol' => $config['protocol'],
|
|
// 'SMTPHost' => $config['SMTPHost'],
|
|
// 'SMTPUser' => $config['SMTPUser'],
|
|
// 'SMTPPass' => $config['SMTPPass'],
|
|
// 'SMTPPort' => $config['SMTPPort'],
|
|
// // 'mailType' => $config['mailType']
|
|
// ]);
|
|
|
|
// $email->setFrom($config['sender_email'], $config['sender_name']);/
|
|
$email->setMailType('html');
|
|
$email->setFrom('bbone@venbait.in', 'BB-Sign');
|
|
$email->setTo($email_id);
|
|
$email->setSubject($subject);
|
|
$email->setMessage($message);
|
|
|
|
|
|
// $email->setMailType('html');
|
|
// $email->setFrom('bbone@venbait.in', 'BB-Sign');
|
|
// $email->setTo($email_id);
|
|
// $email->setSubject($subject);
|
|
// $email->setMessage($message);
|
|
|
|
if ($email->send()) {
|
|
return ['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $email_id];
|
|
} else {
|
|
return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $email_id];
|
|
}
|
|
} catch (\Exception $e) {
|
|
return ['status' => 'failed', 'code' => 500, 'message' => 'Exception: ' . $e->getMessage(), 'data' => $email_id];
|
|
}
|
|
}
|
|
|
|
public static function send_url_email($email_id, $branch_email, $subject, $html, $mail_config = [])
|
|
{
|
|
// try {
|
|
// Merge default config with provided config
|
|
|
|
$email = \Config\Services::email();
|
|
|
|
|
|
$email->initialize([
|
|
'protocol' => $mail_config['protocol'],
|
|
'SMTPHost' => $mail_config['SMTPHost'],
|
|
'SMTPUser' => $mail_config['SMTPUser'],
|
|
'SMTPPass' => $mail_config['SMTPPass'],
|
|
'SMTPPort' => (int)$mail_config['SMTPPort'],
|
|
'mailType' => $mail_config['mailType']
|
|
]);
|
|
|
|
$email->setFrom($mail_config['sender_email'], $mail_config['sender_name']);
|
|
$email->setTo($email_id);
|
|
$email->setSubject($subject);
|
|
$email->setMessage($html);
|
|
|
|
if ($email->send()) {
|
|
return ['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $email_id];
|
|
} else {
|
|
log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers']));
|
|
return ['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $email_id];
|
|
}
|
|
// } catch (\Exception $e) {
|
|
// log_message('error', 'Exception occurred while sending email: ' . $e->getMessage());
|
|
// return ['status' => 'failed', 'code' => 500, 'message' => 'Exception: ' . $e->getMessage(), 'data' => $email_id];
|
|
// }
|
|
}
|
|
|
|
|
|
public static function check_mail_config($r_email, $mail_config = [])
|
|
{
|
|
if (empty($mail_config['protocol']) || empty($mail_config['SMTPHost']) ||
|
|
empty($mail_config['SMTPUser']) || empty($mail_config['SMTPPass']) ||
|
|
empty($mail_config['SMTPPort']) || empty($mail_config['mailType']) ||
|
|
empty($mail_config['sender_email']) ) {
|
|
return json_encode(['status' => 'failed', 'code' => 400, 'message' => 'Incomplete Mail Configuration', 'data' => $r_email]);
|
|
}
|
|
|
|
$email = \Config\Services::email();
|
|
$email->initialize([
|
|
'protocol' => $mail_config['protocol'],
|
|
'SMTPHost' => $mail_config['SMTPHost'],
|
|
'SMTPUser' => $mail_config['SMTPUser'],
|
|
'SMTPPass' => $mail_config['SMTPPass'],
|
|
'SMTPPort' => (int)$mail_config['SMTPPort'],
|
|
'mailType' => $mail_config['mailType']
|
|
]);
|
|
|
|
$email->setFrom($mail_config['sender_email'], '');
|
|
$email->setTo($r_email);
|
|
$email->setSubject("Test Mail Configuration");
|
|
$email->setMessage("Test Mail Configuration");
|
|
|
|
if ($email->send()) {
|
|
return json_encode(['status' => 'success', 'code' => 200, 'message' => 'Email Sent Successfully...', 'data' => $r_email]);
|
|
} else {
|
|
log_message('error', 'Email sending failed: ' . $email->printDebugger(['headers']));
|
|
return json_encode(['status' => 'failed', 'code' => 404, 'message' => 'Email Sent Failed...', 'data' => $r_email]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
?>
|