dongpan9760 2012-11-21 15:55
浏览 38
已采纳

PHPMailer + Cron =重复的电子邮件

When I use the PHPMailer library, my script runs fine from CLI, but when I run it using cron, multiple emails get sent out. I have a list of addresses to send to, then for every next mail recipient, excluding the first one, it sends duplicates.

Example:

I send a message to 3 mail recipients every ten minutes

1st recipient received same email once.

2nd recipient received same email twice.

3rd recipient received same email three times.

4th recip. four times... etc..

The Code:
http://pastebin.com/XjtgEN8u

The crontab :

0,10,20,30,40,50 * * * * /etc/webmin/cluster-cron/cron.pl 1353486136-28420
  • 写回答

3条回答 默认 最新

  • dongzhang1864 2012-11-21 15:59
    关注

    The problem is that you're not creating a new PHPMailer object for each email you're sending. The result is that you're storing all the email addresses already sent to (in previous loops), and resending to them on all subsequent loops. That's why you get incremental duplication.

    To fix the problem, put this line inside your while loop:

    $mail = new PHPMailer(true);
    

    That will instantiate a new mail object for each email address, and reset your email list to 0 before adding the new one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!