Created
April 17, 2016 04:21
-
-
Save iammilton82/add4a3b981ddf0c5f1b8069d24a75a1b to your computer and use it in GitHub Desktop.
Mailgun APi Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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