Skip to content

Instantly share code, notes, and snippets.

Embed
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);
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
You can’t perform that action at this time.