| Server IP : 192.169.170.185 / Your IP : 216.73.216.97 Web Server : Apache System : Linux p3plmcpnl495852.prod.phx3.secureserver.net 4.18.0-553.52.1.lve.el8.x86_64 #1 SMP Wed May 21 15:31:29 UTC 2025 x86_64 User : akhilnew ( 1712764) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/akhilnew/public_html/libraries/ |
Upload File : |
<?php
class Sendgrid {
public $reply = '', $replyEmail = '', $from = '', $fromEmail = '', $cc = '', $bcc = '';
public function send($to = null, $subject = null, $body = null, $attachmentFiles = null)
{
if (is_null($to) OR is_null($subject) OR is_null($body)) {
return false;
}
$emails = explode(',', $to);
foreach ($emails as $email) {
$headers = array(
'Authorization: Bearer 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',
'Content-Type: application/json'
);
$data = array(
'personalizations' => array(
array(
'to' => array(
array(
'email' => trim($email),
)
)
)
),
'from' => array(
'email' => $this->fromEmail,
'name' => $this->from,
),
'reply_to' => array(
'email' => $this->replyEmail,
'name' => $this->reply,
),
'subject' => $subject,
'content' => array(
array(
'type' => 'text/html',
'value' => $body
)
)
);
if ($this->cc) {
foreach (explode(',', $this->cc) as $k => $cc) {
$ccs[$k]['email'] = trim($cc);
}
$data['personalizations'][0]['cc'] = $ccs;
}
if ($this->bcc) {
foreach (explode(',', $this->bcc) as $k => $bcc) {
$bccs[$k]['email'] = trim($bcc);
}
$data['personalizations'][0]['bcc'] = $bccs;
}
if (isset($attachmentFiles) && is_array($attachmentFiles) && count($attachmentFiles) > 0) {
foreach ($attachmentFiles as $k => $attachment) {
$attachments[$k]['content'] = base64_encode(file_get_contents($attachment));
$attachments[$k]['type'] = 'text/html';
$attachments[$k]['filename'] = basename($attachment);
}
$data['attachments'] = $attachments;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/mail/send');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
}
}
}
?>