Chris Stormer
asked on
Parsing bouncing emails in PHP
Hi to everyone,
I have one difficult question about parsing bounced emails.I have manage to retrive info from bounced email such as:
From: MAILER-DAEMON@email.com (Mail Delivery System)
To: error@email.com
Date: Fri, 22 Sep 2006 16:58:13 -0500 (CDT)
Subject: Undelivered Mail Returned to Sender
Message body
The Postfix program : Host or domain name not found. Name service error for name=fs.gov type=A: Host not found
But I can't get final recipient(the recipient to whom email is sent).Can somebody explains to me how to retrive that info.
Thanks in advance
I have one difficult question about parsing bounced emails.I have manage to retrive info from bounced email such as:
From: MAILER-DAEMON@email.com (Mail Delivery System)
To: error@email.com
Date: Fri, 22 Sep 2006 16:58:13 -0500 (CDT)
Subject: Undelivered Mail Returned to Sender
Message body
The Postfix program : Host or domain name not found. Name service error for name=fs.gov type=A: Host not found
But I can't get final recipient(the recipient to whom email is sent).Can somebody explains to me how to retrive that info.
Thanks in advance
How do you retrieve the other data? Can you be a bit more specific?
ASKER
I'm mostly using imap php functions...I have a class for receiving mails and function that I use is this one:
function getHeaders($mid) // Get Header info
{
$mail_header=imap_header($ this->maru box,$mid);
//print_r($mail_header);
$sender=$mail_header->from [0];
$sender_replyto=$mail_head er->reply_ to[0];
$mail_details=array(
'dated'=>$mail_header->Mai lDate,
'from'=>strtolower($sender ->mailbox) .'@'.$send er->host,
'fromName'=>$sender->perso nal,
'toOth'=>strtolower($sende r_replyto- >mailbox). '@'.$sende r_replyto- >host,
'toNameOth'=>$sender_reply to->person al,
'subject'=>$mail_header->s ubject,
'to'=>strtolower($mail_hea der->toadd ress)
);
return $mail_details;
}
If You need anything specific or You want to check whole class I could send it to You.
function getHeaders($mid) // Get Header info
{
$mail_header=imap_header($
//print_r($mail_header);
$sender=$mail_header->from
$sender_replyto=$mail_head
$mail_details=array(
'dated'=>$mail_header->Mai
'from'=>strtolower($sender
'fromName'=>$sender->perso
'toOth'=>strtolower($sende
'toNameOth'=>$sender_reply
'subject'=>$mail_header->s
'to'=>strtolower($mail_hea
);
return $mail_details;
}
If You need anything specific or You want to check whole class I could send it to You.
ASKER
Does my comment make any sence?
Could someone at list point me to something cause I'm stack for two days and there is no way out..
Could someone at list point me to something cause I'm stack for two days and there is no way out..
Sorry, I didn't reply any sooner...
Try this:
function getHeaders($mid) // Get Header info
{
$mail_header=imap_header($ this->maru box,$mid);
//print_r($mail_header);
$sender=$mail_header->from [0];
$sender_replyto=$mail_head er->reply_ to[0];
$recipient = $mail_header->to[0];
$mail_details=array(
'dated'=>$mail_header->Mai lDate,
'from'=>strtolower($sender ->mailbox) .'@'.$send er->host,
'fromName'=>$sender->perso nal,
'toOth'=>strtolower($sende r_replyto- >mailbox). '@'.$sende r_replyto- >host,
'toNameOth'=>$sender_reply to->person al,
'subject'=>$mail_header->s ubject,
'to'=>strtolower($mail_hea der->toadd ress),
'toRecipient'=>$recipient- >personal
);
return $mail_details;
}
$recipient is an array like $sender, so toRecipient in the $mail_details array should contain the to email address...
Try this:
function getHeaders($mid) // Get Header info
{
$mail_header=imap_header($
//print_r($mail_header);
$sender=$mail_header->from
$sender_replyto=$mail_head
$recipient = $mail_header->to[0];
$mail_details=array(
'dated'=>$mail_header->Mai
'from'=>strtolower($sender
'fromName'=>$sender->perso
'toOth'=>strtolower($sende
'toNameOth'=>$sender_reply
'subject'=>$mail_header->s
'to'=>strtolower($mail_hea
'toRecipient'=>$recipient-
);
return $mail_details;
}
$recipient is an array like $sender, so toRecipient in the $mail_details array should contain the to email address...
ASKER
I have try this one but it didn't helped.I have put print_r($recipient) just to see what kind of data I got and I got message:
stdClass Object ( [mailbox] => error [host] => email.com ).
Maybe I wasn't clear in my needs so I will give You an example from the message I got from webmin readmail section:
This is form of message that I get from webmin read mail section.As U can see I have manage to retrieve From,To,Date,Subject and Message text.Only thing that I need right now is Failed delivery status(Final recipient) at the bottom of this message.
From MAILER-DAEMON@email.com (Mail Delivery System)
To error@email.com
Date Thu, 28 Sep 2006 16:26:00 -0500 (CDT)
Subject Undelivered Mail Returned to Sender
Message text
This is the Postfix program at host email.com.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The Postfix program
<aemory@farmersagent.com>: host mxpool.postoffice.net[165. 212.65.113 ] said: 550
<aemory@farmersagent.com>. .. User not known (in reply to RCPT TO command)
Failed delivery status
<b>Final recipient aemory@farmersagent.com<b>
Reason for failure host mxpool.postoffice.net[165. 212.65.113 ] said:
Reporting mail server email.versatables.com
If You need anything else please tell me cause You are the only person that have some interest in my problem.
Thanx.
stdClass Object ( [mailbox] => error [host] => email.com ).
Maybe I wasn't clear in my needs so I will give You an example from the message I got from webmin readmail section:
This is form of message that I get from webmin read mail section.As U can see I have manage to retrieve From,To,Date,Subject and Message text.Only thing that I need right now is Failed delivery status(Final recipient) at the bottom of this message.
From MAILER-DAEMON@email.com (Mail Delivery System)
To error@email.com
Date Thu, 28 Sep 2006 16:26:00 -0500 (CDT)
Subject Undelivered Mail Returned to Sender
Message text
This is the Postfix program at host email.com.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The Postfix program
<aemory@farmersagent.com>:
<aemory@farmersagent.com>.
Failed delivery status
<b>Final recipient aemory@farmersagent.com<b>
Reason for failure host mxpool.postoffice.net[165.
Reporting mail server email.versatables.com
If You need anything else please tell me cause You are the only person that have some interest in my problem.
Thanx.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have manage to fix this problem.Thanx man You helped me a lot.
You're welcome :)