【问题标题】:how to deal with mail per hour limit in phpmailer如何处理phpmailer中的每小时邮件限制
【发布时间】:2014-04-30 20:42:32
【问题描述】:

我正在使用 PHP 邮件程序,它工作正常,除了我认为主机限制为每小时 100 个。 下面是发送 100 后发出的调试信息。

SERVER -> CLIENT: 550 enquiries@**.me 超出速率限制 (100.2 / 1h) 2014-04-30 19:01:30 SMTP 错误: DATA 命令失败: 550 enquiries@ **.me 超出速率限制 (100.2 / 1h) SMTP 错误:数据不被接受。 SMTP 错误:数据不被接受。

我需要发送大约 1600 封电子邮件(大约每 2 周一次),但在有限制的情况下不知道如何做到这一点。

关于如何执行此操作的任何建议,无需每小时返回并手动运行脚本,直到所有电子邮件都发送完毕。

希望这是发布这个问题的正确地方,只有我用谷歌搜索并找不到任何简单的答案(除了联系主持人......)

如果有脚本可以解决这个问题,下面是我正在使用的代码

if($result = $user_obj->getAllNewsletterWhereActive($db)){
        try {
            // initiate object for mail and set smtp
            $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
            $mail->IsSMTP(); // telling the class to use SMTP           
            $mail->SMTPKeepAlive = true;// keep the SMTP open (remember to close at end of script)


            $mail->Host       = "mail.******.me"; // SMTP server
            $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->Host       = "mail.******.me"; // sets the SMTP server
            $mail->Port       = 587;                    // set the SMTP port for the GMAIL server
            $mail->Username   = "enquiries@*******.me"; // SMTP account username
            $mail->Password   = "*******";        // SMTP account password
            $mail->AddReplyTo('enquiries@******.me');
            $mail->SetFrom('enquiries@******.me');
            $mail->AddReplyTo('enquiries@******.me');
            $mail->Subject = $Subject;
            $mail->isHTML(true);  



            foreach($result as $row) {
                // build simple unsubscribe link
                $resetCode = base64_encode($row->NewsletterEmail);
                $websiteLink = 'http://'.$_SERVER['HTTP_HOST'].'/unsubscribe.php?code='.$resetCode;

                $mail->Timeout    =   60; // set the timeout (seconds)
                $mail->Body = $Message.'<br><br>Please click the below link to unsubscribe <br><a href="'.$websiteLink.'">Unsubscribe</a>'; // 
                $mail->AddAddress($row->NewsletterEmail);

                // send email and output success or fail massage
                if($mail->Send()){
                    $message .= 'Message Sent OK to '.$row->NewsletterEmail.'<br>';
                }
                else {
                    $error .= 'Message FAILED to '.$row->NewsletterEmail.'<br>';
                }

                // clear the address for the next loop
                $mail->clearAddresses();                
            }

            // close SMTP conncetion
            $mail->SmtpClose();

        } 
        catch (phpmailerException $e) {         
            echo $e->errorMessage(); //Pretty error messages from PHPMailer         
        } 
        catch (Exception $e) {          
            echo $e->getMessage(); //Boring error messages from anything else!          
        }

    }
    else {
        $error .= '<strong>Error! </strong>There was no email addresses returned or selected. please try again or contact support!<br>';
    }

非常感谢任何建议!

【问题讨论】:

  • 嗯,你需要禁用限制...
  • 在每个之间添加一个sleep(60),以将您的限制设置为每小时 60 件? (每个之间有 60 秒的延迟,即一分钟)。不过,您可以稍微降低它以提高到 100/小时的速度。 (当然,不要在 Web 请求中执行此操作 - 将其作为服务器上的控制台/cron 进程执行)。
  • 问题解决了吗?我有一个类似的gmail

标签: php email phpmailer


【解决方案1】:

是这样的:

  1. 将电子邮件传递队列保存到数据库。
  2. 使用 cronjob 并每小时发送 100 封电子邮件(或 99 以确保安全)

就是这样! :)

PS主持人不太可能解除限制。您还可以查看 Amazon SES、SendGrid、SMTP.com 和此类服务。

【讨论】:

  • 谢谢,这就是答案,看来我需要做更多的工作:-(
【解决方案2】:

不确定这是否会对您有所帮助,但几个月前它为我解决了同样的问题 http://m.youtube.com/watch?v=tlqmbNtW_x8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    相关资源
    最近更新 更多