Created
November 14, 2016 23:07
-
-
Save AugustMiller/333a159161d5fab8ce81ebfe34d37ada to your computer and use it in GitHub Desktop.
Kirby + Mailgun HTML Email service
This file contains hidden or 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
| <? 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