0

I'm working on my little ticketing-system based on PHP.

Now I would like to exclude senders from being processed.

This is a possible list of excluded senders:

Array ( 
"[email protected]",
"example.org",
"[email protected]"
)

Okay - now I would like to check if the sender of an mail matches one of these:

$sender = "[email protected]";

I think this is quite easy, I think I could solve this with in_array().

But what about

$sender = "[email protected]";

example.org is defined in the array, but not [email protected] - but [email protected] should also excluded, because example.org is in the forbidden-senders-list.

How could I solve this?

2 Answers 2

1

Maybe you are looking for stripos function.

<?php

if (!disallowedEmail($sender)) { // Check if email is disallowed
    // Do your stuff
}

function disallowedEmail($email) {
    $disallowedEmails = array ( 
        "[email protected]",
         "example.org",
         "[email protected]"
     )
     foreach($disallowedEmails as $disallowed){
         if ( stripos($email, $disallowed) !== false)
             return true;
     }
     return false
}
Sign up to request clarification or add additional context in comments.

1 Comment

i would use stripos
0

Another short alternative with stripos, implode and explode functions:

$excluded = array( 
"[email protected]",
"example.org",
"[email protected]"
);

$str = implode(",", $excluded);  // compounding string with excluded emails
$sender = "[email protected]";
//$sender = "[email protected]";

$domainPart = explode("@",$sender)[1];  // extracting domain part from a sender email

$isAllowed = stripos($str, $sender) === false && stripos($str, $domainPart) === false;

var_dump($isAllowed);    // output: bool(false)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.