问题描述
编辑:
我认为它与 URL Rewrites 有关,但即使禁用了那些,它仍然会发送两封电子邮件。我的主题只是一个使用 rand() 的随机数,并且每封电子邮件中的数字都不同,这似乎表明该脚本实际上运行了两次,但这对我来说没有意义。
我正在运行这段代码,这是我所能得到的最简单的代码,没有重定向或任何东西,但脚本似乎运行了不止一次。
<?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();
?>
############################################ ###############################
原帖:
我有一个 PHP 脚本,它使用 PHPMailer 发送电子邮件,该脚本运行两次并多次发送电子邮件。我知道是 PHP 脚本运行了两次,因为我在 PHP 中向电子邮件主题添加了一个随机数,并且每封电子邮件中的数字都不相同。
现在,我也在使用 Web.Config 进行 URL 重写,我在网站图标的错误日志中看到了 404。我正在阅读这可能是重写规则导致文件多次加载的原因,但即使在我的包含目录中放置 favicon.ico 也不能解决问题,而且我还没有遇到任何其他解决方案。
这是完整的重写规则...
<?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>
我不认为这本身会导致这个问题,但在这一点上我真的很茫然。
任何人都遇到过类似的问题并提出了解决方案。我将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)