Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Created November 14, 2016 23:07
Show Gist options
  • Save AugustMiller/333a159161d5fab8ce81ebfe34d37ada to your computer and use it in GitHub Desktop.
Save AugustMiller/333a159161d5fab8ce81ebfe34d37ada to your computer and use it in GitHub Desktop.
Kirby + Mailgun HTML Email service
<? email::$services['mailgun-html'] = function($email) {
if(empty($email->options['key'])) throw new Error('Missing Mailgun API key');
if(empty($email->options['domain'])) throw new Error('Missing Mailgun API domain');
$url = 'https://api.mailgun.net/v2/' . $email->options['domain'] . '/messages';
$auth = base64_encode('api:' . $email->options['key']);
$headers = array(
'Accept: application/json',
'Authorization: Basic ' . $auth
);
$data = array(
'from' => $email->from,
'to' => $email->to,
'subject' => $email->subject,
'html' => $email->body,
'h:Reply-To' => $email->replyTo,
);
$email->response = remote::post($url, array(
'data' => $data,
'headers' => $headers
));
if($email->response->code() != 200) {
throw new Error('The mail could not be sent!');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment