What are the best practices for generating fake email addresses using PHP?

Generating fake email addresses using PHP can be useful for testing purposes or creating dummy accounts. One common approach is to concatenate a random string with a predefined domain to create a fake email address. It's important to ensure that the generated email addresses are unique and do not already exist in a database.

// Function to generate a fake email address
function generateFakeEmail() {
    $randomString = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
    $domain = "example.com";
    $fakeEmail = $randomString . "@" . $domain;
    
    return $fakeEmail;
}

// Example of generating a fake email address
$fakeEmail = generateFakeEmail();
echo $fakeEmail;