php - 在特定日期发送电子邮件提醒并且不知道 cron 工作
问题描述
遇到与在某个特定日期发送电子邮件提醒相关的问题。我搜索了一些有用的代码,并且有几个网站提到了 cron 工作。但我对此一无所知。所以任何人都让电话告诉我实际的答案。这里我附上代码。
include('connection.php');
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$datenoted = $_POST['datenoted'];
$subject = $_POST['subject'];
$sel = "insert into reminders(remindr_name,remindr_mobile,reminder_email,remindr_subject,remindr_date,curdate,curtime) values('$name','$mobile','$email','$subject','$datenoted',CURDATE(),CURTIME())";
if(!mysqli_query($link ,$sel ))
{
echo "Error " .mysqli_error($link);
}
else
{
$sqlCommand = "SELECT
u.remindr_id
, remindr_name
, remindr_subject
, remindr_date
, reminder_email
FROM reminders u
WHERE remindr_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
";
$query = mysqli_query($link, $sqlCommand) or die (mysqli_error($link));
//fetch the data from the database
$message = '';
$email = '';
while ($row = mysqli_fetch_array($query)) {
$arr_ids[] = $row['remindr_id'];
$prev_Email = $email;
$headers = "From: mail@georgeprojects.com\r\n";
$subject = "GeorgeProject Reminder";
$id = $row['id'];
$owner = $row['remindr_name'];
$email = $row['reminder_email'];
if(date("Y-m-d") == $row['remindr_date']) {
if(!empty($email) && $email != ""){
$message = "Hi: {$row['remindr_name']} , \n\n There is a reminder for you on the date : {$row['remindr_date']} regarding the subject {$row['remindr_subject']}\n";
$to = $email;
$sendmail = mail($to, $subject, $message, $headers);
}
}
}
header('Location: reminderInsert.php');
}
}
解决方案
推荐阅读
- git - 从损坏的标头恢复本地分支
- python - 看门狗函数的命令行参数
- ember.js - 选择文件后的操作
- ruby - 使用 Carrierwave 将图像从 png 转换为 jpg
- php - 在控制器 Magento 2 中获取当前产品信息?
- java - 使用特定于路由的 DLQ 配置 Java/Camel/AMQ
- arrays - 矩阵列/行删除的 MATLAB 内存管理
- javascript - Ember.js - classNameBindings 正在删除从外部添加的类
- c# - 如何针对 Active Directory 正确验证用户身份?
- serverless-framework - 使用无服务器框架通过部署调用 lambda 函数