Are there any potential conflicts with the system that could be causing the emails to be sent twice?

The issue of emails being sent twice could potentially be caused by duplicate calls to the email sending function in the code. To solve this issue, you can add a check before sending the email to ensure that it is only sent once.

// Check if the email has already been sent
if (!$email_sent) {
    // Send the email
    mail($to, $subject, $message, $headers);
    
    // Set the flag to indicate that the email has been sent
    $email_sent = true;
}