Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

xkts's avatar
Level 5

How to set a webhook for Mailgun?

Hello,

My app - among other things - sends emails to customers. The emails are delivered through MailGun. I am trying to setup a webhook for Mailgun, so that I am informed when a mail has been delivered.

I have set up a Route in routes/api.php as follows:

Route::post('project-name/webhooks/mailgun_info', 'MailgunController@info');

and in the MailgunController.php:

public function info(Request $request){
    dd($request->all());
}

I thought this would be the minimum setup to receive info from MailGun but the webhook test returns:

TokenMismatchException in VerifyCsrfToken.php line 68

My setup is obviously wrong. Does anyone have experience with MailGun API? What would you change to make this work?

0 likes
4 replies
DeanKH's avatar

I've ran into the exact same issue. Did you ever figure this out?

xkts's avatar
Level 5

@DeanKH No, I haven't figured it out yet. Tried a few things after I asked the question but I had no success. When I find the answer, I will add it here.

@alexhackney Thanks for the suggestion. I will try that and get back.

IrishDev's avatar

app/Middleware/VerifyCsrfToken.php

protected $except = [ 'project-name/webhooks/mailgun_info/*' ];

1 like

Please or to participate in this conversation.