I'm using the native Mailgun driver in Laravel 5 to send an email
\Mail::send('emails.notification', $data, function($message) use ($data)
{
$message->to('[email protected]', 'Joe Bob')->subject("Headline here");
});
That works well and the emails are being received, but I would like to know how I can get a response from Mailgun letting me know that the email was sent.
How can I go about getting that information?
To know the status of the email you can use Mailgun webhooks. From the Mailgun admin area you can specify a webhook url that Mailgun will post to after they have processed your email.
Ensure that whatever url you use as a webhook exists in your application and has a route and method in whichever controller you are using. Once your application receives the posted data you can parse the data sent and determine the status of the email. You can then update your database or whatever you need to do.
To identify which email you will need to add some custom headers in the email so you can identify it later on.
see this answer for more details on how to do that: Using Laravel's Mailgun driver, how do you (gracefully) send custom data and tags with your email?
The webhook url needs to be live for it to work, so if you are testing locally with laravell homestead you can take a look at ngrok, which allows you to tunnel your local environment to a url which will work for testing purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With