douxuanou2787 2017-01-05 17:22
浏览 114


I have a very simple script that sends a periodic email from the server to confirm that everything is working ok. The email is sent to only one address and every time, two identical emails are sent.There are no loops, no database calls for additional addresses. Everything is set and fixed in the script.

There are a ton of similar questions on this topic. All deal with a slightly different situation - adding addresses, occasional duplicates, etc. - and I've carefully followed the advice in each. I've also followed the advice of @Synchro to read the PHPMailer docs carefully. Specifically I have:

  • simplified the interactions down to the simplest code - forget the chron job, forget gathering the data for the email, etc. (see below)
  • upgraded to the latest version of PHPMailer
  • looked for use of $mail->send() in a conditional statement per this post (could not find any)
  • turned Apache's rewrite engine off, thinking that a possible server redirect was duplicating the request (and restarted server)
  • used firebug to detect duplicate get requests for the page (only one request is shown)
  • disabled all plugins and extensions in firefox and restarted firefox
  • tried the same script in Chrome
  • set the debug notice level for smtp to 1; nothing earth shattering here, the script runs once
  • compared the email Message-IDs. The Message-ID in the smtp debug message and BOTH emails are identical
  • moved relevant scripts to different dev environment

In every case I get the same result - 2 identical emails get sent with the same Message-IDs with exactly the same time stamp.

The simplified test_send_mail.php calling script:

$subject = 'TEST PHP_MAILER';
$msg = 'this is only a test';
$mail = new send_mail('','',$subject,$msg);

The send_mail class looks like this:


require 'class.phpmailer.php';
require 'class.smtp.php';

class send_mail {

    function __construct($to='',$from='',$subject='[no subject]',$body='[no content]') {
        if(empty($to)) {
            $to = DEFAULT_RECIPIENT;

        if(empty($from)) {
            $from = SYS_ADMIN;

        $this->ready_mail = $this->set_parameters($to,$from,$subject,$body);


    function set_parameters($to,$from,$subject,$body) {
        $mail = new PHPMailer(true); // true = throw exceptions on errors


        try {
            $mail->Host = SMTP_SERVER; 
            $mail->SMTPDebug = 0;       //0 = none; 1 = some; 2 = all
            $mail->SMTPAuth = true; 
            $mail->SMTPSecure = 'ssl';
            $mail->Port = SMTP_PORT;        
            $mail->Username = SMTP_USERNAME;
            $mail->Password = SMTP_PASSWORD;
            //for php5.6 to bypass SSL check
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true

            $mail->WordWrap = 50;   
            $mail->isHTML(true);        // Set email format             

            $mail->FromName = 'UHMS SysAdmin';
            //for local only
            $mail->Subject = $subject.' *local*';
            //for production only
            //$mail->Subject = $subject;
            $mail->Body = $body;

        } catch (phpmailerException $e) {

        } catch (Exception $e) {
            pp('send_mail exception',$e->getMessage());

        return $mail;       

    function send_it() {

        echo '<br>sending...';


PHPMail_core.php simply defines the default values (CAPITALIZED_TERMS) used in the send_mail class, nothing more.

The environment is: PHP 7.0.13/PHPMailer 5.2.21/Apache 2.4.23

What else could possibly be causing the duplicate emails?

  • 写回答

1条回答 默认 最新

  • doudiaozhi6658 2017-01-07 00:39

    Well the bottom line is that the phenomenon described above was totally caused by an "operator error". Sometime in the past, I had set up an email filter rule in cPanel for the recipient email account. The rule effectively caused a duplicate delivery of this particular email. It's weird that I wasn't getting duplicates of other emails, but indeed, as soon as the offending rule was removed, the duplicate emails described above ceased...and all emails seem to be coming through just fine. So the root cause had nothing to do with PHPMailer, the hosting company, Thunderbird or the code.

    The filter rule was created long ago and far away so wasn't the obvious cause. I'm memorializing the conclusion here just in case it helps. Let it be proof that the tracks you lay can sometimes lead you in the wrong direction...

    Totally appreciate all the help provided by others in getting to this embarrassing conclusion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 nrf52810-c三个a 程序
  • ¥15 lego-loam跑出来的roll误差很大
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对