Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.22.74.192
<?php
$main_src_obj=(explode("/",$_SERVER["REQUEST_URI"]));
$main_src=$_SERVER["DOCUMENT_ROOT"]."/".$main_src_obj[1];
$main_src=(dirname($_SERVER[SCRIPT_FILENAME]));
require_once $main_src.'/Swift4/lib/swift_required.php';
class CMailer {
function __construct($aarr_mailer_info) {
ini_set("memory_limit",-1);
ini_set('max_execution_time', 1400);
$this->marr_mailer_info = $aarr_mailer_info;
$this->transport = Swift_SmtpTransport::newInstance('smtp.gmail.com222222', 465, "ssl")->setUsername('sstarkasoft@gmail.com')->setPassword('tarka123');
//$this->transport = Swift_SmtpTransport::newInstance('mail.sreecharanbank.com', 587)->setUsername('website@sreecharanbank.com')->setPassword('website');
$this->mailer = Swift_Mailer::newInstance($this->transport);
}
public function send_mail()
{
$larr_mandatory_fields = array(
'subject',
'body',
'from' ,
'to'
);
foreach ($larr_mandatory_fields as $key => $value) {
if (!array_key_exists($value, $this->marr_mailer_info)) {
throw new Exception('Required mailer information not present / need to pass proper format');
}
}
# Checking if atleast one value is passed for 'to' address
if( !is_array($this->marr_mailer_info['to']) || count($this->marr_mailer_info['to']) < 1 ) {
throw new Exception('The TO address is invalid / need to pass proper format');
}
# Checking if 'from' address is passed correctly
if( !is_array($this->marr_mailer_info['from']) || count($this->marr_mailer_info['from']) != 2 ) {
throw new Exception('The FROM address is invalid / need to pass proper format');
}
$this->subject = $this->marr_mailer_info['subject'];
$this->body = $this->marr_mailer_info['body'];
$this->from = $this->marr_mailer_info['from'];
$this->to = $this->GetEmailIdsArr($this->marr_mailer_info['to']);
$this->cc = $this->GetEmailIdsArr($this->marr_mailer_info['cc']);
$this->bcc = $this->GetEmailIdsArr($this->marr_mailer_info['bcc']);
$this->mobj_swift_addr = Swift_Message::newInstance($this->marr_mailer_info['subject']);
# Setting To address(es) of the mail
$this->mobj_swift_addr->setTo($this->to);
$this->mobj_swift_addr->setcc($this->cc);
$this->mobj_swift_addr->setbcc($this->bcc);
$this->mobj_swift_addr->setFrom(array( $this->from['email'] => $this->from['name']));
$this->mobj_swift_addr ->setBody($this->body, 'text/html');
;
if(is_array($this->marr_mailer_info['attachments'])) {
foreach($this->marr_mailer_info['attachments'] as $key => $value) {
$this->mobj_swift_addr->attach(Swift_Attachment::fromPath($value['file_source']));
}
}
$result = $this->mailer->send($this->mobj_swift_addr);
return $result;
}
function GetEmailIdsArr($arr)
{
$data_array=array();
if(empty($arr))
return $data_array;
foreach($arr as $key => $value)
{
array_push($data_array,$value['email']);
}
return $data_array;
}
}
?>
|