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_r
ing 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