使用邮件函数 PHP 发送了多少封电子邮件


how many email have been sent using mail function php

有没有办法找出从php邮件功能发送的电子邮件总数。我的邮件功能在 while 循环内,我想知道发送的电子邮件数量。

谢谢

如果您只想知道 while 循环中接受投递的邮件数量,请添加一个计数器变量:

$mailsSent = 0;
while($condition) {
    if (mail('foo@example.com', 'My Subject', 'My Message')) {
        $mailsSent++;
    }
}
echo $mailsSent;

对于接受传递的邮件总数,您可以使用 php 配置文件.ini

mail.log字符串

将记录所有mail()调用的日志文件的路径。日志条目包括脚本的完整路径、行号、收件人地址和标头。

参考: http://php.net/manual/en/mail.configuration.php#ini.mail.log

如果您想知道实际发送的邮件数量,请检查 sendmail 日志。

重新编辑了答案!请立即检查。一开始我很困惑!

您可以使用以下方式检查已发送的邮件数:

<?php
    $count = 0;
    while ($condition) {
        if(mail($to, $subject, $message))
            $count++;
    }
    echo "Totally, $count messages have been sent!";
?>