Actually I am doing code to find the bounced mail. I am placing the source code of the full email to match. one of my email giving above error. So I need to check for that error contain in email code or not. If that code found then it will return error accordingly. So in that error message dynamic parts are email address, ip in square brackets and the string mailbox unavailable. The string I need to find is as below, dynamic portion are covered in bold text: The mail system <aaa@asg.com>: host mx2.hotmail.com[65.55.92.152] said: 550 Requested action not taken: mailbox unavailable (in reply to RCPT TO command) So first it check for email address like <demo@email.com>, then for IP address like [12.25.65.85] and then a string "mailbox unavailable". Order must be this.
you can get the individual parts from regexlib.com and then join them using a + so that one or more matches are pointed out. regards, d_s.
Use this regex: preg_match('/<aaa@asg\.com>.*\[65\.55\.92\.152\].*mailbox unavailable.*/Uism',$content); PHP: Just make sure you always escape the periods and brackets.
@PHPMaster can you let me know, what if i want the regexp for IP address also rather than static IP you have mentioned. and what the Uism will do here?
Just plugin the PHP variables: preg_match('/<'.$email.'>.*\['.$ip.'].*mailbox unavailable.*/Uism',$content); PHP: Just make sure you escape any dots in the IP/email. For PHP regular expression modifiers (Uism), check this link: http://php.net/manual/en/reference.pcre.pattern.modifiers.php