0

I am using Postmark to send emails. But postmark allows you to set a URL to process bounced emails. I want to use this, but don't know how to get and handle the data.

My API works but I don't know how to retrieve the data postmark sends to my API.

<?php

class BackendBillingAPI
{
    public static function postmarkBounceHook()
    {
        $log = new SpoonLog('custom', PATH_WWW . '/backend/cache/logs/billing');

        // logging when we are in debugmode
        if(SPOON_DEBUG) $log->write('Billing post (' . serialize($_POST) . ') triggered.');
        if(SPOON_DEBUG) $log->write('Billing get (' . serialize($_GET) . ') triggered.');
        if(SPOON_DEBUG) $log->write('Billing _REQUEST (' . serialize($_REQUEST) . ') triggered.');

    }
}

Any thoughts/ideas?

Bart
  • 19,692
  • 7
  • 68
  • 77
Frederik Heyninck
  • 3,493
  • 4
  • 20
  • 19

1 Answers1

1

You'd need to parse the json data inside the POST, and you can't rely on _POST apparently (since this is not a multipart form, see this for more info)

Here's a simple code that grabs a few parameters from the postmark bounce and generates an email. You can grab the parameters and do whatever else you need to of course

<?php
$form_data = json_decode(file_get_contents("php://input"));

// If your form data has an 'Email Address' field, here's how you extract it:     
$email_address = $form_data->Email;
$details = $form_data->Details;
$type = $form_data->Type;

// Assemble the body of the email...                                              
$message_body = <<<EOM
Bounced Email Address: $email_address
Details: $details
Type: $type
EOM;
if ($email_address) {
    mail('ENTER YOUR EMAIL ADDRESS',
         'Email bounced!',
         $message_body);
}
?>
Community
  • 1
  • 1
gingerlime
  • 5,206
  • 4
  • 37
  • 66