Created
June 25, 2013 21:50
-
-
Save oomathias/5862778 to your computer and use it in GitHub Desktop.
Get your email with your own domain thanks to Mandrill. You need to host the script somewhere, and point Mandrill Inbound webhook to it.
Don't forget to include the Mandrill PHP library. If you user composer, you just have to do composer install.
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
{ | |
"require": { | |
"mandrill/mandrill": "1.0.34" | |
} | |
} |
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
<?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