-
-
Save anilex/71f158835b05eb6502910c8680b83a7e to your computer and use it in GitHub Desktop.
Very simple PHP webhook for Mailgun that emails you on errors.
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 | |
$key = "<API Key>"; | |
$from = "[email protected]"; | |
$to = "[email protected]"; | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
if(isset($_POST['timestamp']) && isset($_POST['token']) && isset($_POST['signature']) && hash_hmac('sha256', $_POST['timestamp'] . $_POST['token'], $key) === $_POST['signature']) | |
{ | |
if($_POST['event'] == 'complained') { | |
$subject = "[Mailgun] Spam Complaint"; | |
$body = "Recipient: " . $_POST['recipient'] . "\nDomain: " . $_POST['domain'] . "\n\nMessage-headers: " . $_POST['message-headers'] . "\n"; | |
mail($to, $subject, $body, "From: " . $from,"-f". $from); | |
}elseif($_POST['event'] == 'bounced'){ | |
$subject = "[Mailgun] Bounced Email"; | |
$body = "Recipient: " . $_POST['recipient'] . "\nDomain: " . $_POST['domain'] . "\nCode: " . $_POST['code'] . "\nError: " . $_POST['error'] . "\nNotification: " . $_POST['notification'] . "\n\nMessage-headers: " . $_POST['message-headers'] . "\n"; | |
mail($to, $subject, $body, "From: " . $from,"-f". $from); | |
}elseif($_POST['event'] == 'dropped'){ | |
$subject = "[Mailgun] Failed Email"; | |
$body = "Recipient: " . $_POST['recipient'] . "\nDomain: " . $_POST['domain'] . "\nCode: " . $_POST['code'] . "\nReason: " . $_POST['reason'] . "\nDescription: " . $_POST['description'] . "\n\nMessage-headers: " . $_POST['message-headers'] . "\n"; | |
mail($to, $subject, $body, "From: " . $from,"-f". $from); | |
} | |
} | |
} | |
header('X-PHP-Response-Code: 200', true, 200); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I made use of this method for getting emails from Mailgun using the webhooks - but they have now made those webhooks legacy and will be getting rid of them at some point. I don't suppose you have got a similar working method for the new webhooks they have added?? thanks