| 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/temp/ |
Upload File : |
<?php
class Mail
{
public $to, $subject, $message, $fromEmail, $fromName, $replyEmail, $replyName, $attachments = array();
public function create($to, $subject, $message)
{
$this->to = $to;
$this->subject = $subject;
$this->message = $message;
return $this;
}
public function from($email, $name)
{
$this->fromEmail = $email;
$this->fromName = $name;
return $this;
}
public function reply($email, $name)
{
$this->replyEmail = $email;
$this->replyName = $name;
return $this;
}
public function attach($attachment)
{
$this->attachments[] = $attachment;
return $this;
}
public function send()
{
$headers = array(
'Authorization: Bearer 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',
'Content-Type: application/json'
);
$data = array(
'personalizations' => array(
array(
'to' => array(
array(
'email' => $this->to,
)
)
)
),
'from' => array(
'email' => $this->fromEmail,
'name' => $this->fromName,
),
'reply_to' => array(
'email' => $this->replyEmail,
'name' => $this->replyName,
),
'subject' => $this->subject,
'content' => array(
array(
'type' => 'text/html',
'value' => $this->message
)
)
);
if (!empty($this->attachments) && isset($this->attachments) && is_array($this->attachments)) {
foreach ($this->attachments 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);
$this->to = $this->subject = $this->message = $this->fromEmail = $this->fromName = $this->replyEmail = $this->replyName = $this->attachments = null;
}
}