back to phpList.org

Integration with mailgun.com


#1

Just wrote a simple php script to process bounces when using mailgun.com as your SMTP service.
If interested, just upload the script to your phplist directory, enter (in 2nd line) correct API key retrieved from mailgun.com/account settings, and setup in mailgun as a webhook.
https://help.mailgun.com/hc/en-us/articles/202236504-How-do-webhooks-work-

<?php
define('KEY','*******************');
 
 
$er = error_reporting(0);

require_once dirname(__FILE__) . '/admin/inc/unregister_globals.php';
require_once dirname(__FILE__) . '/admin/inc/magic_quotes.php';
## none of our parameters can contain html for now
$_GET = removeXss($_GET);
$_POST = removeXss($_POST);
$_REQUEST = removeXss($_REQUEST);

if (isset($_SERVER['ConfigFile']) && is_file($_SERVER['ConfigFile'])) {
    include $_SERVER['ConfigFile'];
} elseif (is_file('config/config.php')) {
    include 'config/config.php';
} else {
    print "Error, cannot find config file\n";
    exit;
}

require_once dirname(__FILE__) . '/admin/init.php';
if (isset($GLOBALS['developer_email']) && $GLOBALS['show_dev_errors']) {
    error_reporting(E_ALL);
    ini_set('show_errors', 'on');
} else {
    error_reporting(0);
}

$GLOBALS['database_module'] = basename($GLOBALS['database_module']);
$GLOBALS['language_module'] = basename($GLOBALS['language_module']);

require_once dirname(__FILE__) . '/admin/' . $GLOBALS['database_module'];

# load default english and language
include_once dirname(__FILE__) . '/texts/english.inc';
# Allow customisation per installation
if (is_file($_SERVER['DOCUMENT_ROOT'] . '/' . $GLOBALS['language_module'])) {
    include_once $_SERVER['DOCUMENT_ROOT'] . '/' . $GLOBALS['language_module'];
}

include_once dirname(__FILE__) . '/admin/languages.php';
require_once dirname(__FILE__) . '/admin/defaultconfig.php';
require_once dirname(__FILE__) . '/admin/connect.php';
include_once dirname(__FILE__) . '/admin/lib.php';


if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['timestamp']) && isset($_POST['token']) && isset($_POST['signature']) && hash_hmac('sha256', $_POST['timestamp'] . $_POST['token'], KEY) === $_POST['signature'])
{
    if($_POST['event'] == 'bounced' || $_POST['event'] == 'dropped' || $_POST['event'] == 'failed')
    {
        Sql_Query(sprintf('update %s set bouncecount = bouncecount + 1 where email = "%s"', $tables['user'], addslashes($_POST['recipient']) ));
        if (Sql_Affected_Rows()) 
          header('X-PHP-Response-Code: 200', true, 200);
		}
}
else
      header('X-PHP-Response-Code: 406', true, 406);
 
?>

#2

same error…have you found solution ?