Forked from oomathias/Mandrill_inbound_to_outbound.php
Last active
August 29, 2015 14:22
-
-
Save jonathanargentiero/823b3e96e974fe087e4e to your computer and use it in GitHub Desktop.
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
| { | |
| "require": { | |
| "mandrill/mandrill": "1.0.34" | |
| } | |
| } |
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
| <?php | |
| require 'vendor/mandrill/mandrill/src/Mandrill.php'; | |
| define('API_KEY', '123456789QWERTY'); | |
| define('TO_EMAIL', '[email protected]'); | |
| define('TO_NAME', 'Foo Bar'); | |
| if(!isset($_POST['mandrill_events'])) { | |
| echo 'A mandrill error occurred: Invalid mandrill_events'; | |
| exit; | |
| } | |
| $mail = array_pop(json_decode($_POST['mandrill_events'])); | |
| $attachments = array(); | |
| foreach ($mail->msg->attachments as $attachment) { | |
| $attachments[] = array( | |
| 'type' => $attachment->type, | |
| 'name' => $attachment->name, | |
| 'content' => $attachment->content, | |
| ); | |
| } | |
| $headers = array(); | |
| // Support only Reply-to header | |
| if(isset($mail->msg->headers->{'Reply-to'})) { | |
| $headers[] = array('Reply-to' => $mail->msg->headers->{'Reply-to'}); | |
| } | |
| try { | |
| $mandrill = new Mandrill(API_KEY); | |
| $message = array( | |
| 'html' => $mail->msg->html, | |
| 'text' => $mail->msg->text, | |
| 'subject' => $mail->msg->subject, | |
| 'from_email' => $mail->msg->from_email, | |
| 'from_name' => $mail->msg->from_name, | |
| 'to' => array( | |
| array( | |
| 'email' => TO_EMAIL, | |
| 'name' => TO_NAME, | |
| ) | |
| ), | |
| 'attachments' => $attachments, | |
| 'headers' => $headers, | |
| ); | |
| $async = false; | |
| $result = $mandrill->messages->send($message, $async); | |
| print_r($result); | |
| } catch(Mandrill_Error $e) { | |
| // Mandrill errors are thrown as exceptions | |
| echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage(); | |
| // A mandrill error occurred: Mandrill_PaymentRequired - This feature is only available for accounts with a positive balance. | |
| throw $e; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment