Send Email and perform action, add record in Database using Laravel ,Mailgun

Shawinder Jit Singh
1 min readMar 16, 2021

--

I think title is quite interesting.

today we are going to discuss the case when our user sends email and based on that email body our Laravel Application will perform some task.

We will use Mailgun for Inbound Email Process. you can also use custom server or any other third party service like mandrill.

first of all take your subdomain for emails like mail.yourdomain.com which is good practice because DNS Records for original domain will not be changed.

Add domain

Login to mailgun > sending > domains > Add New Domain

enter domain name choose region and save record . now enter the MX,TXT records as per offical documentation https://help.mailgun.com/hc/en-us/articles/360026833053 also at domain verification page mailgun portal confirm about values added in DNS Records . after configuring DNS Settings you need to verify domain .

Add Route to Mailgun

goto Receiving > Create Route> enter web address which is ready to insert values received by mail route ,that’s all from Mailgun.

Laravel in Picture

Create route in laravel as mentioned in Mailgun Routes section and make sure you have done all kind of validations to receive and perform action accordingly.

get values inside controller using below code

$sender = Input::get(‘sender’);

$subject = Input::get(‘subject’);

$body = Input::get(‘stripped-text’);

use these variables for further use.

--

--

Shawinder Jit Singh
Shawinder Jit Singh

Written by Shawinder Jit Singh

Full Stack Web Developer | Crazy for Laravel,React |

No responses yet