Skip to content
PHP Logo

Are there any best practices for organizing and categorizing emails based on user and domain in PHP?

To organize and categorize emails based on user and domain in PHP, one approach is to parse the email address and extract the user and domain parts. Once extracted, you can store the emails in an array or database table with the user and domain as keys or columns for easy retrieval and categorization.

php
$email = "example@example.com";

list($user, $domain) = explode('@', $email);

// Store the email in an array with user and domain as keys
$emails[$user][$domain] = $email;

// Retrieve emails for a specific user and domain
$user = 'example';
$domain = 'example.com';

if(isset($emails[$user][$domain])) {
    echo "Email found: " . $emails[$user][$domain];
} else {
    echo "Email not found for user $user on domain $domain";
}