What are some best practices for handling email forwarding in PHP to avoid sending duplicate emails?

When handling email forwarding in PHP, it's important to keep track of emails that have already been forwarded to avoid sending duplicates. One way to achieve this is by storing a unique identifier for each forwarded email in a database and checking this identifier before forwarding an email. This ensures that each email is only forwarded once.

// Check if the email has already been forwarded
if (!$alreadyForwarded) {
    // Forward the email
    // Your forwarding logic here

    // Store a unique identifier for the forwarded email in the database
    $uniqueIdentifier = generateUniqueIdentifier();
    saveUniqueIdentifierToDatabase($uniqueIdentifier);
}