2

我有一个包含 12,000 多个用户的数据库,我正在尝试向所有用户发送一封电子邮件,每个用户都有一个基于他们在数据库中的信息的特定信息。我已经制作了这封电子邮件,以便在周日早上 6 点运行 cron 时发送,我在上周五完成了该功能,它在周日运行,即昨天。这就是发生的事情。

1.) 这封电子邮件从早上 6 点到晚上 7 点整天都在发送

2.) 到那时,它只发送给 750 个用户

3.)在那之后它完全停止了,原因我不知道

PS:, I am sending the emails using PHPMailer使用模板,我使用循环遍历所有用户并为每个用户执行计算,用信息填写模板然后发送电子邮件。

下面是一个代码片段,显示了我的工作......

foreach($users as $user){
            // Construct the email template
            $htmlContent = file_get_contents(__DIR__ . '/../../templates/weekly_spending_template.html');

            // Replace some place holders with user's custom information.
            $htmlContent = preg_replace('/\$bars/', $bars, $htmlContent);
            $htmlContent = preg_replace('/\$labels/', $labels, $htmlContent);
            $htmlContent = preg_replace('/\$total/', $currency . ' ' . number_format($total, 0), $htmlContent);
            $htmlContent = preg_replace('/\$budget/', $currency . ' ' . number_format($budget, 0), $htmlContent);
            $htmlContent = preg_replace('/\$first_name/', ucfirst($user->first_name), $htmlContent);
            $htmlContent = preg_replace('/\$remark/', $remark, $htmlContent);
            $htmlContent = preg_replace('/\$percentage_difference/', $percentage_difference, $htmlContent);
            $htmlContent = preg_replace('/\$others/', $others, $htmlContent);


            try {
                // Setup email parameters
                $mail = new PHPMailer(true);
                $subject = "Your weekly spending breakdown";


                $mail->IsSMTP();
                $mail->SMTPDebug = 0;
                $mail->SMTPAuth = true;
                $mail->SMTPSecure = "ssl";
                $mail->Host = "smtp.gmail.com";
                $mail->Port = 465;
                $mail->AddAddress($user->email, ucfirst($user->first_name) . ' ' . ucfirst($user->last_name));
                $mail->Username = "mymail@example.com";
                $mail->Password = "myPassW0rd";
                $mail->SetFrom('mymail@example.com', 'Name');
                $mail->AddReplyTo("mymail@example.com", "Name");
                $mail->Subject = $subject;
                $mail->Body = $htmlContent;
                $mail->isHTML(true);

                if (!$mail->send()) {
                    echo "Message was not sent.\n";
                    echo 'Mailer error: ' . $mail->ErrorInfo . "\n";
                } else {
                    echo "Message has been sent.\n";
                }
            } catch (\Exception $ex) {
                echo $ex->getMessage();
            }
}

拜托,任何人都可以就如何使这个过程更有效、更快或更好地实现这一目标的选择给我建议吗?谢谢。

4

2 回答 2

0

您可能会考虑使用 swiftmailer(下面的链接),因为它几乎可以满足您的所有需求,并且被用于许多产品和框架中,因此您可以确定它相当稳定。

https://swiftmailer.symfony.com/docs/sending.html#sending-emails-in-batch

而且您每天只能发送 500 封邮件@20 封邮件/每小时

请参阅: https: //support.google.com/a/answer/2956491#sendinglimitsforrelay

于 2017-09-25T11:46:01.793 回答
-3

只需用逗号分隔它们,例如

$email_to = "youremailaddress@yourdomain.com, emailtwo@yourdomain.com, John Doe <emailthree@example.com>"

有关更多详细信息,请查看此链接:- PHP 将邮件发送到多个电子邮件地址

于 2017-09-25T11:38:57.393 回答