EDIT:
I thought it was related to URL Rewrites, but even with those disabled, it still sends two emails. I have the subject just a random number using rand(), and the number is different in each email, which would seem to indicate that the script is actually being run twice, but this makes no sense to me.
I am running this code, that is as simplified as I can get it, there are no redirects or anything and yet the script seems to be run more than once.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$toEmail = '######@#####.com';
$toName = 'To';
$fromName = 'From';
$fromEmail = '#####@#####.com';
$subject = rand();
$message = 'Test Message';
$mail = new PHPMailer(TRUE);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = TRUE;
$mail->SMTPSecure = 'tls';
$mail->Username = '#####@######.com';
$mail->Password = '#####';
$mail->Port = 587;
$mail->setFrom($fromEmail, $fromName);
$mail->addAddress($toEmail, $toName);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
?>
###############################################################################
ORIGINAL POST:
I have a PHP script that is sending an email with PHPMailer that is running twice and sending an email more than once. I know it is the PHP script running twice because I add a random number in PHP to the email subject, and it is different in each email.
Now, I am also using Web.Config to do URL Rewrites, and I see a 404 in the error log for the favicon. I was reading that could be the reason the rewrite rule is causing the file to load more than once, but even placing a favicon.ico in my includes directory doesn't solve the issue, and I haven't come across any other solutions.
This is the full rewrite rule...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Remove PHP" stopProcessing="false">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}.php" matchType="IsFile" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="{R:1}.php" />
</rule>
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I don't think this could cause this issue on its own, but at this point I am really at a loss.
Anyone experienced a similar issue and come up with a solution. I would greatly appreciate it.