Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

A simple SparkPost webhook base controller for catching bounced, rejected, etc mail events.

License

Notifications You must be signed in to change notification settings

brentnd/laravel-sparkposthooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel 5 / Lumen 5 SparkPost Webhook Controller

Latest Version Software License Total Downloads

A simple SparkPost webhook controller to help with email events. Useful for notifying users that you cannot reach them via email inside your application. Compatible with Laravel 5+ and Lumen 5+.

Installation

composer require brentnd/laravel-sparkposthooks

Basic Usage

  1. Create a controller that extends SparkPostWebhookController as follows. You can then handle any SparkPost webhook event.
use Brentnd\Api\Webhooks\SparkPostWebhookController;

class MySparkPostController extends SparkPostWebhookController {

    /**
     * Handle a bounced email
     *
     * @param $payload
     */
    public function handleMessageEventBounce($payload)
    {
        $email = $payload['rcpt_to'];
    }

    /**
     * Handle a rejected email
     *
     * @param $payload
     */
    public function handleMessageEventPolicyRejection($payload)
    {
        $email = $payload['rcpt_to'];
    }

    /**
     * Handle an email open
     *
     * @param $payload
     */
    public function handleTrackEventOpen($payload)
    {
        $transmissionId = $payload['transmission_id'];
    }
}
  1. Create the route to handle the webhook. In your routes.php file add the following.
post('sparkpost-webhook', ['as' => 'sparkpost.webhook', 'uses' => 'MySparkPostController@handleWebhook']);
  1. Exclude your route from CSRF protection so it will not fail.

  2. Make sure you add your webhook in SparkPost to point to your route. You can do this here: https://app.sparkpost.com/webhooks

Webhook Events

Webhook event types:

Common events and their handlers. For other events, just follow the same pattern.

Event type Event Method
Ping - handlePing()
Message Events Bounce handleMessageEventBounce()
Message Events Delivery handleMessageEventDelivery()
Message Events Injection handleMessageEventInjection()
Message Events Policy Rejection handleMessageEventPolicyRejection()
Message Events Delay handleMessageEventDelay()
Engagement Events Click handleTrackEventClick()
Engagement Events Open handleTrackEventOpen()
Engagement Events Initial Open handleTrackEventInitialOpen()
Unsubscribe Events List Unsubscribe handleUnsubscribeEventListUnsubscribe()
Unsubscribe Events Link Unsubscribe handleUnsubscribeEventLinkUnsubscribe()

Contributors

Based on eventhomes/laravel-mandrillhooks

About

A simple SparkPost webhook base controller for catching bounced, rejected, etc mail events.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages