I am currently working on a project which processes an array of data which is imported from a csv. Once the data has been processed for that specific row, it will send an email to the email address specified for that row.
My client has a requirement that they need to know if an email bounces due to an incorrect email address being entered to the csv.
I currently send the emails by using PHP and an SMTP relay which we host, The only way that i have found to work so far is to scan the sending email address for any emails which contains the subject Undelivered Mail Returned to Sender.
This is working perfectly and i am getting a list of all of the emails which have bounced. My problem is that i need to get the email address which was entered incorrectly. If you see the screenshot below you can see that the script generates an HTML element/node which contains the email address.
My question is, How to i grab/call this element?
I have tried print_ring the email object, unfortunately there is no array index with the email address which i require.
Please see my code below to see how i have gotten this far:
<?php $date = date('y-m-d'); $hostname = ''; $username = ''; $password = ''; $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to mailbox: ' . imap_last_error()); $emails = imap_search($inbox,'SUBJECT "Undelivered Mail Returned to Sender" ON "'.$date.'"'); if($emails){ rsort($emails); foreach($emails as $email){ $overview = imap_fetch_overview($inbox,$email,0); $message = imap_body($inbox, $email); print_r($overview); print_r($message); echo '<br>'; print_r($email); } } Thanks for your excellent help and support over the past.
Lewis

imap_search(), but I see you are using theSUBJECTandONkeywords.. according to php.net/manual/en/function.imap-search.php, there is aTOkeyword. Maybe you can do some magic with the query, some wildcarding maybe? Sorry if I'm pestering and not helping, but what does$emailscontain?$emailsis an array of all of the emails which were returned by the.imap_search$emailcontains basic information such as,sent_date,sent_toandsent_from. Before you saysent_tosounds like what you are asking for. No, the email address specified here is the email address which contains all of the bounced emails. I appreciate your help!