Question

I have following code to get the value from 'To', but the output is Array

$header=imap_headerinfo($inbox,'18');
echo $header->to;

Second I use imap_search function to search through the email & find the desired string in the email body. Now some of the email clients do use different body, so let's say for yahoo. The actual email in Outlook or any other client looks like this:

The mail system

<dkkfdjhfhjd@gmail.com>: host gmail-smtp-in.l.google.com[173.194.77.26] said:
550-5.1.1 The email account that you tried to reach does not exist. Please
try 550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1
http://support.google.com/mail/bin/answer.py?answer=6596
c10si1356788oed.181 - gsmtp (in reply to RCPT TO command)

However when I try to print it by:

$message = imap_fetchbody($inbox,'18',1);
echo $message;

It prints like this:

The mail system : host gmail-smtp-in.l.google.com[173.194.77.26] said: 550-5.1.1
The email account that you tried to reach does not exist. Please try 550-5.1.1 
double-checking the recipient's email address for typos or 550-5.1.1 unnecessary 
spaces. Learn more at 550 5.1.1 http://support.google.com/mail/bin/answer.py?
answer=6596c10si1356788oed.181 - gsmtp (in reply to RCPT TO command)

I cannot get the email address from this as well. Can anyone tell the decent method to get the email address of the users whose delivery got failed? From headers or anything else? I need it badly, can anyone help?

Was it helpful?

Solution

The array you get is an array of addresses.

The best way to get the address that failed is to look at the bodyparts, find the one with content-type message/delivery-status, and parse that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top