ballouta Posted August 9, 2008 Share Posted August 9, 2008 Hello kindly i need an expression that detects this string 'Delivery Status Notification' from the body of the message AND the email address returned: example: This is an automatically generated Delivery Status Notification Delivery to the following recipient failed permanently: [email protected] Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 Requested action not taken: mailbox unavailable (state 14). output needed: [email protected] Thank you very much Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/ Share on other sites More sharing options...
nrg_alpha Posted August 9, 2008 Share Posted August 9, 2008 $str = 'Delivery to the following recipient failed permanently: [email protected] Technical details of permanent failure:.. blah blah blah'; echo $str . '<br />'; // output main string to extract email from... $str = preg_match('#\b.+(@|(\[at\])).+\b#', $str, $match); echo $match[0]; This simple solution ought to do it. It matches anything on either side of either the @ character or [at] characters.. if you don't need to check for the [at] part, you can simply modify the pre_match line to the following: $str = preg_match('#\b.+@.+\b#', $str, $match); Cheers, NRG P.S This is a very loose version.. obvisouly, if people enter some gibberish with the @ symbol somewhere inbetween, this expression will find it.. it doesn't strictly search for properly formated emails... but I am assuming here that the email the system complains about is relatively proper in format... (then again, you know what they say about 'assume' though...) In any case, for general purposes, since the error message seems prefabbed, and again, assuming the email format is respectable, the above expression should work. Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-612440 Share on other sites More sharing options...
ballouta Posted August 9, 2008 Author Share Posted August 9, 2008 Hi nrg_alpha the code works correctly as I want. Thanks for the solution and for the notes. good luck Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-612546 Share on other sites More sharing options...
ballouta Posted August 20, 2008 Author Share Posted August 20, 2008 Hello again the previous solution didn't work on reading a messsage that contains more than 1 email address. for example, if the: <?php $message="This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: [email protected] [email protected] [email protected] [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT "; ?> the output is exactly: [email protected] @ Would you please help. Note: no problem if it outputs repeated email address. but at least output them all without any other data. Thanks Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-621458 Share on other sites More sharing options...
nrg_alpha Posted August 21, 2008 Share Posted August 21, 2008 $message="This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: [email protected] [email protected] [email protected] [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT "; echo $message . '<br /><br />'; preg_match_all('#([^\s<]+@[^\s>]+)#', $message, $matches); for($i = 0, $total = count($matches[0]); $i < $total; $i++){ echo $matches[0][$i] . '<br />'; } Outputs: [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-621552 Share on other sites More sharing options...
ballouta Posted August 21, 2008 Author Share Posted August 21, 2008 Thanks nrg_alpha for your help I can't find the problem in my code that outputs only one email address, kindly have a look on it <?php $str="This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: [email protected] [email protected] [email protected] [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT TO:<[email protected]>: host mx1.hotmail.com [65.54.245.8]: 550 Requested action not taken: mailbox unavailable [email protected] SMTP error from remote mail server after RCPT "; $str = preg_match('#\b.+(@|(\[at\])).+\b#', $str, $match); //echo $message . '<br />'; echo $match[0]; ?> Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-621607 Share on other sites More sharing options...
nrg_alpha Posted August 21, 2008 Share Posted August 21, 2008 Well, since the conditions are now different from the oringinal situation, simply use the exression I just posted the last time: preg_match_all('#([^\s<]+@[^\s>]+)#', $message, $matches); for($i = 0, $total = count($matches[0]); $i < $total; $i++){ echo $matches[0][$i] . '<br />'; } This expression will work better.. it doesn't check word bounderies. Instead, it uses a space or a '<' or '>' character as the bounderies. This is more effective in this situation. The reason you only get one email address ouput is that you are not looping through the $match array. If you notice in the above example, I made a for() loop. Basically, $i = 0, and I set a variable that is the total of the $matches array. Then, so long as $i < the total amount, echo out the current array (which in this case always starts with $matches[0]..so $matches[0][1] will ouput the first email address it found.. $matches[0][2] will ouput the second one, etc.. etc.. Cheers, NRG Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-621867 Share on other sites More sharing options...
ballouta Posted August 21, 2008 Author Share Posted August 21, 2008 Hi NRG The code is now working perfect. Many thanks for you Link to comment https://forums.phpfreaks.com/topic/118933-solved-need-expression-for-returned-emails/#findComment-621912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.