Skip to content

Instantly share code, notes, and snippets.

@FredSRocha
Last active July 6, 2019 09:38
Show Gist options
  • Save FredSRocha/708b3fff6d3465355be1b75047cf0ed2 to your computer and use it in GitHub Desktop.
Save FredSRocha/708b3fff6d3465355be1b75047cf0ed2 to your computer and use it in GitHub Desktop.
Send Grid Class.
<?php
interface IEmail {
public static function sendGrid($email,$subject,$htmlmessage,$plaintext);
}
class SendGridEmail implements IEmail {
public static function sendGrid($email,$subject,$htmlmessage,$plaintext) {
$url = 'https://api.sendgrid.com/';
$user = '***'; // SendGrid User.
$pass = '***'; // SendGrid Password.
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $email,
'subject' => $subject,
'html' => $htmlmessage,
'text' => $plaintext,
'from' => '***@email.com',
);
$request = $url.'api/mail.send.json';
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment