Skip to content

Instantly share code, notes, and snippets.

Created April 17, 2016 04:21
What would you like to do?
Mailgun APi Sample
class Mailgun {
function post($headers, $url, $data){
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($handle);
return $response;
function get($headers, $url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
return $data;
$urlBase = '';
$sendUrl = $urlBase."/messages";
$headers = array();
$data = array();
$data['from'] = '';
$data['to'] = '';
$data['subject'] = 'Sample Email Subject';
$data['html'] = '<p>Sample email body</p>';
$send = new Mailgun;
$send->post($headers, $sendUrl, $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment