将邮件发送给用户并执行代码直到位置标头将需要时间。我希望在另一个线程中运行邮件发送代码,这样定位或加载特定页面就不需要时间了。
$sql = "SELECT email FROM user_info where username = ?";
$statement = $db->prepare($sql);
$statement->bindParam(1, $cmtTo);
$statement->execute();
$row = $statement->fetch();
// echo $row['email'];
$mailSender = new PuzzleEmailSender();
$body = "<html>
<body>
<h2 style=\"font-weight:bold;font-size:24px;font-family:Helvetica,Arial,sans-serif;line-height:26px;color:#999;margin:0\"><img class=\"navbarimg\" src=\"" alt=\"/></h2><br>
<div style=\"font:normal 14px Helvetica,Arial,sans-serif;line-height:19px;color:#333\">
<p>Hi, <strong>" . $cmtTo . "</strong> </p>
<p><strong>" . $cmtBy . "</strong> expressed comment on your puzzle answer</strong></p>
<p><a style=\"text-decoration:underline;color:#00aff0;font-weight:bold\" href='" "' target=\"_blank\">Click on the link to check</a></p>
<p>Team,</p>
<p style=\"font-weight:bold;font-size:15px;line-height:24px;font-family:Arial,Helvetica,sans-serif;color:#666;margin:0\">
" "</p></div>
</div>
</body>
</html>";
$subject = "Comment On Your Answer";
$mailSender->sendQueryEmail($row['email'], "", $body, $subject, "", false);
header("Location: puzzleDisplay");发布于 2016-04-05 13:04:02
创建表:mail_queue
字段:id、email、subject、body
改变:
$mailSender->sendQueryEmail($row['email'], "", $body, $subject, "", false);至
$sql = "INSERT INTO mail_queue SET email = ?, body = ?, subject = ?"
$statement = $db->prepare($sql);
$statement->bindParam(1, $row['email']);
$statement->bindParam(2, $body);
$statement->bindParam(3, $subject);
$statement->execute();创建脚本:mail_queue.php,它将提取所有电子邮件并进行邮件发送,然后删除发送后的记录
放到crontab:* ** php mail_queue.php
发布于 2016-04-05 13:08:11
你可以在后台发送邮件。将邮件任务添加到某个队列中,然后定期执行队列。
可以通过多种方式实现这些目标:
gearman-job-server。将邮件从主脚本中放入作业服务器中。然后用gearman worker脚本编写发送电子邮件的代码。iron.io。Laravel使用铁api。https://stackoverflow.com/questions/33407647
复制相似问题