PHPMailer在加载google chrome页面时超时


PHPMailer timing out google chrome page when loading

所以我有PHPMailer设置正确,我有唯一的部分都设置了PHP的消息。

目前,我只是有一个PHP网页,它首先检索所有的电子邮件需要从数据库之前,它通过每个电子邮件和发送它。不幸的是,当我试图给数据库30封电子邮件时,我去了chrome中的php文件,在我最终得到chrome上的超时消息之前,它只是白色的几分钟。目前我不知道发送了多少电子邮件,但我要问的是,我如何才能发送页面上的所有电子邮件,同时不导致页面超时

这里是我的流程的快速概述

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Maketting</title>
</head>
<body>
<?php
require "../api/access.php";
require "../api/api.php";

echo "<h1>Please wait....</h1>";
$sql = "SELECT * FROM `Points` WHERE `points` >='10'";
$result = sqlStatment($sql);
$emails = array();
while($row = mysqli_fetch_array($result)) {
    $Name = $row['name'];
    $email = "null";
    $sqlnew = "SELECT `Student Email`  FROM `Orders` WHERE `Student UID` = '".$row['uid']."' LIMIT 0,1";
    $resultnew =  sqlStatment($sqlnew);
        while($row = mysqli_fetch_array($resultnew)) {
          $email=$row['Student Email'];
        }
   array_push($emails, array("name" => $Name,"email" =>  $email));
}
?>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
    <thead>
    <tr>
        <th>Date and time</th>
        <th>User Name</th>

    </tr>
    </thead>
    <tbody>
    <?
    $last = count($emails) - 1;
    foreach ($emails as $i => $row)
    {
        $isFirst = ($i == 0);
        $isLast = ($i == $last);
        echo "<tr>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['email'] . "</td>";

        echo "</tr>";
    }

?>
    </tbody>
</table>
    <?php

    require '../mail/load.php';
    $last = count($emails) - 1;
    foreach ($emails as $i => $row) {
        $isFirst = ($i == 0);
        $isLast = ($i == $last);
        $name = $row['name'];
        $email = $row['email'];
        if (!$email = "n/a") {
            $mail = new PHPMailer;
//$mail->SMTPDebug = 3;                               // Enable verbose debug output
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = '';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = '';                 // SMTP username
            $mail->Password = '';                           // SMTP password
            $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 25;                                    // TCP port to connect to
            $mail->setFrom('', 
            $mail->addAddress($email, $name);     // Add a recipient
            // Name is optional
            $mail->addReplyTo('', '');

            // Optional name
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = '';
            $mail->Body = '

        ';
            $mail->AltBody = 'Hi there,

';
            if (!$mail->send()) {
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
            } else {
                echo "<br>Email Sent to " . $name . "<br>";
            }
        }
    }
?>
</body>
</html>

你的发送效率非常低,每次在发送循环周围创建一个PHPMailer实例,这意味着你不能使用keepalive。查看PHPMailer提供的邮件列表示例,了解如何更有效地发送邮件。除此之外,正如其他人所说,将此作为cron作业运行。您还可以通过运行本地邮件服务器使其运行得更快,因为提交到本地邮件服务器将更快,并让邮件服务器处理到目的地的缓慢传递。这也将处理交付延迟(重试),超时,连接不良,反弹等。