我有一个超过12,000个用户的数据库,我正在尝试向所有用户发送电子邮件,每个用户根据他们在数据库中的信息提供特定信息。我已经发了这封电子邮件,当一个cron在星期日早上6点运行并且我在上周五完成了这个功能并且它在星期天运行,即昨天。发生了什么。
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();
}
}
拜托,有人可以向我提出如何使这一过程更有效,更快或更好的选择来实现这一目标的建议吗?感谢。
答案 0 :(得分:0)
您可以考虑使用swiftmailer(链接下方),因为它大部分都是您想要的并且在许多产品和框架中使用,因此您可以确定它相当稳定。
每天只能发送500封邮件@每小时20封邮件
请参阅:https://swiftmailer.symfony.com/docs/sending.html#sending-emails-in-batch
答案 1 :(得分:-3)
用逗号分隔它们,比如
'axios error:', { [Error: Request failed with status code 500]
config:
{ adapter: [Function: xhrAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded' },
method: 'post',
'Content-Type': 'application/json',
Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjEsImlzcyI6Imh0dHA6Ly9hcHBzZGF0YTIuY2xvdWRhcHAubmV0L2p3dC1kZW1vL3B1YmxpYy9hcGkvbG9naW4iLCJpYXQiOjE1MDYzMzkwNDgsImV4cCI6MTY2MTg1OTA0OCwibmJmIjoxNTA2MzM5MDQ4LCJqdGkiOiJHUWt5RVlwck5GSDBHekd4In0.JqdyAEkEN_D3M2WbqcQwIwghk6iajFjxi9g854akjB8',
url: 'http://appsdata2.cloudapp.net/jwt-demo/public/api/profile',
data: null },
request:
{ UNSENT: 0,
OPENED: 1,
HEADERS_RECEIVED: 2,
LOADING: 3,
DONE: 4,
readyState: 4,
status: 500,
timeout: 0,
withCredentials: true,
upload: {},
_aborted: false,
_hasError: false,
_method: 'POST',
_response: '{"meta":{"message":"Unable to get token in your request."}}',
_url: 'http://appsdata2.cloudapp.net/jwt-demo/public/api/profile',
_timedOut: false,
_trackingName: 'unknown',
_incrementalEvents: false,
responseHeaders:
{ expires: '-1',
pragma: 'no-cache',
Server: 'nginx',
Date: 'Mon, 25 Sep 2017 11:30:49 GMT',
'Keep-Alive': 'timeout=60',
'Content-Type': 'application/json',
'Content-Length': '59',
Connection: 'keep-alive',
'X-RateLimit-Remaining': '58',
'X-Powered-By': 'PHP/5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1',
'Cache-Control': 'private, must-revalidate',
'X-RateLimit-Limit': '60' },
_requestId: null,
_cachedResponse: undefined,
_headers:
{ accept: 'application/json, text/plain, */*',
'content-type': 'application/x-www-form-urlencoded' },
_responseType: '',
_sent: true,
_lowerCaseResponseHeaders:
{ expires: '-1',
pragma: 'no-cache',
server: 'nginx',
date: 'Mon, 25 Sep 2017 11:30:49 GMT',
'keep-alive': 'timeout=60',
'content-type': 'application/json',
'content-length': '59',
connection: 'keep-alive',
'x-ratelimit-remaining': '58',
'x-powered-by': 'PHP/5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1',
'cache-control': 'private, must-revalidate',
'x-ratelimit-limit': '60' },
_subscriptions: [],
responseURL: 'http://appsdata2.cloudapp.net/jwt-demo/public/api/profile' },
response:
{ data: { meta: { message: 'Unable to get token in your request.' } },
status: 500,
statusText: undefined,
headers:
{ expires: '-1',
pragma: 'no-cache',
server: 'nginx',
date: 'Mon, 25 Sep 2017 11:30:49 GMT',
'keep-alive': 'timeout=60',
'content-type': 'application/json',
'content-length': '59',
connection: 'keep-alive',
'x-ratelimit-remaining': '58',
'x-powered-by': 'PHP/5.6.23-1+deprecated+dontuse+deb.sury.org~trusty+1',
'cache-control': 'private, must-revalidate',
'x-ratelimit-limit': '60' },
config:
{ adapter: [Function: xhrAdapter],
transformRequest: { '0': [Function: transformRequest] },
transformResponse: { '0': [Function: transformResponse] },
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
validateStatus: [Function: validateStatus],
headers:
{ Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded' },
method: 'post',
'Content-Type': 'application/json',
有关详细信息,请点击此链接: - PHP send mail to multiple email addresses