156 lines
4.5 KiB
PHP
156 lines
4.5 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
if (!function_exists('send_emails')) {
|
|
|
|
function send_emails($to, $subject, $body, $aliasName = '', $cc = null, $bcc = null, $receipt = null)
|
|
{
|
|
|
|
log_message('info', 'send_mail_helper_loadded');
|
|
log_message('info', 'Receiptent mail - '.$to.' - subject - '.$subject.' - body - '.$body);
|
|
log_message('info', 'Sender mail '.business()->sender_mail);
|
|
|
|
|
|
try {
|
|
$mailer = new PHPMailer(true);
|
|
log_message('info', 'phpmailer loaded');
|
|
|
|
$mailer->isSMTP();
|
|
$mailer->CharSet = 'utf-8';
|
|
$mailer->Host=business()->mail_hostname;
|
|
$mailer->SMTPSecure = business()->mail_security;
|
|
$mailer->SMTPAuth =true;
|
|
$mailer->SMTPDebug = 2;
|
|
$mailer->Username=business()->mail_username;
|
|
$mailer->Password=business()->mail_password;
|
|
$mailer->Port=business()->mail_port_no;
|
|
$mailer->setFrom(business()->sender_mail, $aliasName);
|
|
$mailer->addAddress($to);
|
|
|
|
// Add CC recipients
|
|
if ($cc !== null) {
|
|
if (is_array($cc)) {
|
|
foreach ($cc as $ccRecipient) {
|
|
$mailer->addCC($ccRecipient);
|
|
}
|
|
} else {
|
|
$mailer->addCC($cc);
|
|
}
|
|
}
|
|
|
|
// Add BCC recipients
|
|
if ($bcc !== null) {
|
|
if (is_array($bcc)) {
|
|
foreach ($bcc as $bccRecipient) {
|
|
$mailer->addBCC($bccRecipient);
|
|
}
|
|
} else {
|
|
$mailer->addBCC($bcc);
|
|
}
|
|
}
|
|
|
|
$mailer->Subject=$subject;
|
|
$mailer->isHTML(true);
|
|
$mailer->Body=$body;
|
|
|
|
$attachmentPath = '/path/to/your/attachment/' . $receipt;
|
|
|
|
if (file_exists($attachmentPath)) {
|
|
$mailer->addAttachment($attachmentPath);
|
|
}
|
|
|
|
$mailer->send();
|
|
|
|
return true;
|
|
log_message('info', 'success : mail sendsuccessfully');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return 'Error: ' . $mailer->ErrorInfo;
|
|
log_message('info', 'Error : '.$mailer->ErrorInfo);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!function_exists('send_emails_forgot_password')) {
|
|
|
|
function send_emails_forgot_password($to, $subject, $body, $aliasName = '', $cc = null, $bcc = null, $receipt = null)
|
|
{
|
|
|
|
log_message('info', 'send_mail_helper_loadded');
|
|
log_message('info', 'Receiptent mail - '.$to.' - subject - '.$subject.' - body - '.$body);
|
|
log_message('info', 'Sender mail '.business()->sender_mail);
|
|
|
|
|
|
try {
|
|
$mailer = new PHPMailer(true);
|
|
log_message('info', 'phpmailer loaded');
|
|
|
|
$mailer->isSMTP();
|
|
$mailer->CharSet = 'utf-8';
|
|
$mailer->Host='smtp.sendgrid.net';
|
|
$mailer->SMTPSecure = 'tls';
|
|
$mailer->SMTPAuth =true;
|
|
$mailer->SMTPDebug = 2;
|
|
$mailer->Username='apikey';
|
|
$mailer->Password='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';
|
|
$mailer->Port='587';
|
|
$mailer->setFrom('no-reply@tripapprovaltool.com');
|
|
$mailer->addAddress($to);
|
|
|
|
// Add CC recipients
|
|
if ($cc !== null) {
|
|
if (is_array($cc)) {
|
|
foreach ($cc as $ccRecipient) {
|
|
$mailer->addCC($ccRecipient);
|
|
}
|
|
} else {
|
|
$mailer->addCC($cc);
|
|
}
|
|
}
|
|
|
|
// Add BCC recipients
|
|
if ($bcc !== null) {
|
|
if (is_array($bcc)) {
|
|
foreach ($bcc as $bccRecipient) {
|
|
$mailer->addBCC($bccRecipient);
|
|
}
|
|
} else {
|
|
$mailer->addBCC($bcc);
|
|
}
|
|
}
|
|
|
|
$mailer->Subject=$subject;
|
|
$mailer->isHTML(true);
|
|
$mailer->Body=$body;
|
|
|
|
$attachmentPath = '/path/to/your/attachment/' . $receipt;
|
|
|
|
if (file_exists($attachmentPath)) {
|
|
$mailer->addAttachment($attachmentPath);
|
|
}
|
|
|
|
$mailer->send();
|
|
|
|
return true;
|
|
log_message('info', 'success : mail sendsuccessfully');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return 'Error: ' . $mailer->ErrorInfo;
|
|
log_message('info', 'Error : '.$mailer->ErrorInfo);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|