所以我正确设置了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>
答案 0 :(得分:0)
您发送效率非常低,每次在发送循环周围创建一个PHPMailer实例,这意味着您无法使用keepalive。请查看the mailing list example provided with PHPMailer了解如何更有效地发送内容。除此之外,正如其他人所说,将其作为一项计划工作。您也可以通过运行本地邮件服务器来提高速度,因为提交速度会快得多,让邮件服务器处理到目的地的速度缓慢。这也将涉及交付延期(重试),超时,连接不良,跳出等。