Krish Krish - 2 months ago 13
PHP Question

Issue processing incoming emails in mailgun

I want to process the json (recieved through post request from mailgun of incoming email).

I'm using codeigniter.

Following is a portion the json that I'm dealing with.

},
"log-level": "info",
"timestamp": 1475215276.814206,
"message": {
"headers": {
"to": "helpdesk@example.com",
"message-id": "CALv887xt-=_ijgb1iC0BQcOwJXguOWbiF7j+Licx6kqperh5Zg@mail.gmail.com",
"from": "User Test <user.test@gmail.com>",
"subject": "example email for testing"
},
"attachments": [],
"recipients": [
"53954680dacd5416eedb3f8639ece5f9@email.example.com"
],


I do not have any problem accessing the from value
$this->input->post('from')
and subject value
$this->input->post('subject')
.

However I'm trying to access the to and recipients with the following code, but all I'm getting is null values.

$to = $this->input->post('to');

$message_header = $this->input->post('message');
$recipients = $message_header->recipients;
$email = $recipients[0];
$email_q = filter_var($email, FILTER_SANITIZE_EMAIL);


Any help would be great.

Answer

Got the to address in the following way.

In Codeigniter:

$this->input->post('recipient');

In PHP:

$_POST['recipient'];
Comments