How can the issue of duplicate emails being sent in PHP be resolved effectively?

Issue: The problem of duplicate emails being sent in PHP can be resolved effectively by implementing a check to ensure that an email is not sent multiple times within a short period. This can be achieved by setting a flag in the database or session to mark an email as already sent, and checking this flag before sending the email.

// Check if email has already been sent
if(!isset($_SESSION['email_sent'])) {
    // Send email
    // Your email sending code here

    // Set flag to mark email as sent
    $_SESSION['email_sent'] = true;
}