gpt4 book ai didi

PHPMailer 在发送群发邮件时挂起

转载 作者:可可西里 更新时间:2023-10-31 23:36:21 24 4
gpt4 key购买 nike

我已经成功地在 centos 服务器上使用 PHP、PHPmailer 设置了一个网络应用程序,用于向客户发送批量电子邮件。客户电子邮件从 SQL 数据库中获取。它成功运行并发送一封电子邮件并休眠 20 秒,然后循环执行此过程。该数据库有 6000 个电子邮件地址。在此过程中,服务器通过发送大约 100 封电子邮件而挂起。所以我必须再次运行这个程序。为什么会挂起?我没有收到 PHP 错误或 PHP 超时。

这是我的代码:`

<?php

require 'PHPMailerAutoload.php';
$con = mysql_connect("localhost", "root", "test");
mysql_select_db("user", $con);
$query = "select email from client_detail";
$result = mysql_query($query, $con);
$email = array();
while ($row = mysql_fetch_assoc($result)) {
$email[] = $row['email'];
}
foreach ($email as $to) {
$mail = new PHPMailer;
$mail->setFrom('bestweb@nic.lk');
$mail->addAddress($to);
$mail->Subject = 'Bestweb2018';
$mail->isHTML(true);
$mail->Body = '<html>
<head>
<title>BestWeb.lk 2018</title>
</head>
<body>
<table style="width: 760px;" >
<tr>
<td>
<img src="cid:banner" alt="bestweb.lk 2018" width="760px" height="167px" />
</td>
</tr>
</table>
</body>
</html>
';
$mail->AddEmbeddedImage('images/bannergold.gif', 'banner');

if (!$mail->send()) {
echo 'Message was not sent ' . $to;
echo "<br>";
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent ' . $to;
echo "<br>";
}

sleep(20);
}
?>

最佳答案

由于每次迭代 20 秒 sleep sleep(20),服务器可能会过载。

Reduce sleep time to few seconds like 2 or 3.

sleep(3)

Enable display errors, add this top of the script

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Log email completion status on log file because you are running a loop all echo data goes to buffer so nothing would get print until loop gets finished.

if (!$mail->send()) {
@file_put_contents('email-logs.txt', 'Message was not sent ' . $to ." - error :" . var_export( $mail->ErrorInfo, true) . "\n", FILE_APPEND);
} else {
@file_put_contents('email-logs.txt', 'Message has been sent ' . $to . "\n", FILE_APPEND);
}

关于PHPMailer 在发送群发邮件时挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49401487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com