PHP

Store email reply to our database in php

Store email reply to our database in php

Store email reply to our database in php. I am using basecamp for my applications. When ever I add to d0 or updated to I will receive the email from basecamp with to do ID as reply email. If I give a reply It want to send email as well update in my basecamp to do. I felt its one of the cool stuff. If we are going to use comment system means these kind of features will add more flexibility to the users. After a long research found the solution to implement this logic.

There are may ways to achieve this. By using Mandrill or Sendgrid we can achieve this easily. We have php imap functionality which will read the incoming emails. By using this we can able to read incoming email for static given email id, We cannot make a dynamic email id based on post id. But by using mandrill we can implement this.

Lets see how to achieve this,

Step 1 : Create Mandrill account

Step 2 : Go to Settings [In left side bar] => Domains => Add your domain name

Mandril Settings
mandrill-settings
Mandrill Domain

mandrill-settings-domain

Step 3 : Add DKIM Settings & SPF Settings TXT records in mentioned domains, By clicking View DKIM settings & View SPF settings you can see txn records => In My case I have domain in godaddy so added MX records under DNS management

DKIM Record

mandrill-settings-dkim-record

SPF Record

mandrill-settings-spf-txn

Step 4 : Click “Test DNS Settings” to check, the TXT records are added successfully or not. If you added successfully you can see green tick like my screen grab.

Step 5 : Click Inbound Menu at left side bar

mandrill-inbound

Step 6 : Add your domain in below of Inbound Domains Text box

Step 7 : Click View Setup Instructions button on the top right

mandrill-inbound-mx-records

Step 8 : Add Showing both of the MX Records in your domain => In My case I have domain in godaddy so added MX records under DNS management

Step 9: Click Test DNS Settings button to check Mx records are added successfully or not

Step 10 : Click your added domain name to add webhook and click save

Webhook => It will post the inbound emails to given url

Step 11 : Click +Add New Route button

mandrill-inbound-webhook

Step 12 : In Text box you can give static email address or global

Store email reply

For eg : *@domain.com // Global => It will redirect all emails for this domian to given url

For eg : info@domain.com // Global => It will redirect only info@domain.com emails for this domian to given url

Step 13 : Enter the URL where mandrill want to Inbound your emails

Step 14 : Write your code to fetch inbound email datas in your mentioned url file. In my case I am using PHP.

How to add dynamic id in reply-to email :

In our webhook email address we have mentioned as “*”, So what event the email before ******@yourdomain.com will read in your given webhook url . So Just create dynamic id and place it under header reply to email id.

Eg :

Here in my case 8765092 is my post Id, So based on it will update my table.

How to get read inbound emails in PHP and Store in database

The below code was return in the page where we given webhook url.

Here I have stored read data in txt file as well as stored in DB

Read datas from web hook and store email reply to database

To Parse Reply Text use below code

 

Thats all now you can read email and store email reply to your database

Hope it will help someone.