Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@iammilton82
Created April 17, 2016 04:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iammilton82/add4a3b981ddf0c5f1b8069d24a75a1b to your computer and use it in GitHub Desktop.
Save iammilton82/add4a3b981ddf0c5f1b8069d24a75a1b to your computer and use it in GitHub Desktop.
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);
curl_close($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);
curl_close($ch);
return $data;
}
}
$urlBase = 'https://api:mailgun-key@api.mailgun.net/v3/domain-name.com';
$sendUrl = $urlBase."/messages";
$headers = array();
$data = array();
$data['from'] = 'noreply@domain-name.com';
$data['to'] = 'sample@domain-name.com';
$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