74 lines
2.7 KiB
PHP
Executable File
74 lines
2.7 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
class Notification
|
|
{
|
|
protected $email;
|
|
protected $logger;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->email = service('email');
|
|
$this->logger = service('logger');
|
|
}
|
|
|
|
public function sendEmail($records)
|
|
{
|
|
$this->logger->error('Helper : Email Request Data type = '.gettype($records));
|
|
|
|
$cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
|
|
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
|
|
|
|
try {
|
|
$this->email->clear();
|
|
if($records['recipient_email'] == "" && $records['subject'] == ""){
|
|
throw new \Exception("Email and Subject are Must Please Try again..");
|
|
}
|
|
$this->email->setTo($records['recipient_email']);
|
|
$this->logger->error('Helper : Email recipient = '.$records['recipient_email']);
|
|
|
|
$this->email->setFrom($records['from_mail'], isset($records['company'])?$records['company']:"RI Pvt Ltd");
|
|
$this->email->setSubject($records['subject']);
|
|
$this->logger->error('Helper : Email subject = '.$records['subject']);
|
|
|
|
$this->email->setMessage($records['description']);
|
|
|
|
if ($cc !== '') {
|
|
$ccRecipients = explode(',', trim($cc));
|
|
$this->logger->error('Helper : Email carbon copy CC recipient = ' . implode(',', $ccRecipients));
|
|
if (!empty($ccRecipients)) {
|
|
$this->email->setCC($ccRecipients);
|
|
}
|
|
}
|
|
// else {
|
|
// $this->email->setCC('vadivel.j@venbainfotech.com');
|
|
// }
|
|
|
|
if ($bcc !== '') {
|
|
$bccRecipients = explode(',', trim($bcc));
|
|
$this->logger->error('Helper : Email blindcarboncopy BCC recipient = ' . implode(',', $bccRecipients));
|
|
if(!empty($bccRecipients)) {
|
|
$this->email->setBCC($bccRecipients);
|
|
}
|
|
}
|
|
// else{
|
|
// $this->email->setCC('gowtham.m@venbainfotech.com');
|
|
// }
|
|
|
|
if ($this->email->send()) {
|
|
$message['success'] = 'Email sent successfully';
|
|
$this->logger->error('Helper : Email Status = sent successfully');
|
|
} else {
|
|
throw new \Exception('Email sending failed.');
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->logger->error('Helper : Email Error = ' . $e->getMessage());
|
|
$message['error'] = 'Email Exception Occur : ' . $e->getMessage();
|
|
}
|
|
return $message;
|
|
}
|
|
}
|
|
|
|
?>
|