Well, you can use preg or other functions to match, but, this is more of a logical problem. First, the hospital name contains caps and spaces and may be spelled differently that the address in the email. You can check if the hospital name exists in the email with some tricky code, but, it may not work for all inputs.
Business names do not always match the incoming email. As you see in your example, the email1 is a gmail address and would not match the hospital name. If you want to just see if the hospital name is inside the text for the email1, you could do it something like this…
function php_match_function($email, $hospital) {
// Explain... Remove spaces from hospital name, remove upper case, check if in email
if( strpos(strtolower($email), strtolower(str_replace(" ", "", $hospital)))==0 ) {
return false;
} else {
return true;
}
}
This removes the spaces from hospital name, checks if that string is inside the email text and returns true or false as needed. Remember that functions use LOCAL data, so you can use the same names as outside the function and they are not altered. But, if the company name is “The Tommy Business” and the email1 is “[email protected]”, then it would be false. Hard to sort out this type of validation. But, hope this helps…