- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我对创建服务器每天运行的服务器脚本和作业还很陌生。
我的问题如下:
我想向我的用户发送一封电子邮件,提醒他们必须完成的特定工作。
我的想法:
数据库->收集所有需要通知的用户,插入到表notify_user
脚本 -> 查找所有用户并向他们发送邮件
脚本 -> 从表中删除所有内容
此脚本将在每天的特定时间运行,例如每 24 小时运行一次。
正如我之前所说,我并不真正热衷于如何设置这样的脚本。
我的服务器是 Ubuntu 服务器,我的应用程序是 PHP 程序。
有谁知道我如何实现这一点,或者知道我在哪里可以找到关于这个主题的一些文档,因为我一直找不到任何解决这个问题的方法。
最佳答案
如果您知道如何填充“notify_user”表,那么这些是我为您重现解决方案示例的步骤。我在运行 sendmail 守护程序的 VPS 服务器上执行了此操作。
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 167
Server version: 5.5.40-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database stack_mail_db;
Query OK, 1 row affec`enter code here`ted (0.05 sec)
mysql> grant all privileges on stack_mail_db.* to 'stack_mail_usr'@'localhost' identified by 'stack_mail_pass';
Query OK, 0 rows affected (0.11 sec)
mysql> use stack_mail_db;
Database changed
mysql> create table notify_user( id int not null auto_increment primary key, user_name tinytext, user_email tinytext );
Query OK, 0 rows affected (0.28 sec)
创建这个示例数据库后,我们应该用至少 2 个用户(用于测试)和工作电子邮件填充它。我在这里更改了我使用的实际电子邮件。
mysql> insert notify_user (user_name, user_email) values ('test1', 'test1@test.com');
Query OK, 1 row affected (0.18 sec)
mysql> insert notify_user (user_name, user_email) values ('test2', 'test2@test.net');
Query OK, 1 row affected (0.03 sec)
现在我们应该编写一个脚本来获取这些详细信息并发送电子邮件:
# vim cron_email.php
<?php
$host = 'localhost';
$user = 'stack_mail_usr';
$pass = 'stack_mail_pass';
$dbname = 'stack_mail_db';
$conn = new mysqli($host, $user, $pass, $dbname);
if ($conn->connect_error) {
trigger_error('DB connection failed: ' . $conn->connect_error, E_USER_ERROR);
}
$query = 'select * from notify_user';
$res = $conn->query($query);
if ($res === false) {
trigger_error('Failed query: ' . $query . ' Error: ' . $conn->error, E_USER_ERROR);
}
$headers = 'From: admin@example.com' . "\r\n" .
'Reply-To: admin@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$res->data_seek(0);
while ($row = $res->fetch_assoc()) {
$to = $row['user_email'];
$subject = 'Notification for ' . $row['user_name'];
$message = 'Hello ' . $row['user_name'];
$mail = mail($to, $subject, $message, $headers);
if ($mail) {
$conn->query('delete from notify_user where id=' . $row['id']);
} else {
echo "Email failed\n";
}
}
现在是时候将这个脚本放在 cron 上了:
# crontab -e
0 0 * * * php -f /path/to/cron_email.php
这将在每个午夜恰好运行您的脚本。如果您想设置更具体的时间,请查看本教程: http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
希望对您有所帮助^)
关于php - Linux 服务器 : Send mail to my users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27022246/
我很难理解为什么这段代码无法编译: use std::cell::{Ref, RefCell}; struct St { data: RefCell } impl St { pub f
我从Richard Blum的一本书《 C#网络编程》中读到有关套接字的信息。以下摘录指出,不保证Send()方法可以发送所有传递给它的数据。 byte[] data = new byte[1024]
我有以下程序,它必须一次读取 1MB 的文件,将其发送到服务器(每次总是 1MB)并返回哈希码: #include #include #include #include #include #
代码在底部。 第 207 行的 send() 命令本身可以正常工作。但是,当我在第 218 行添加 send() 命令时,第一个命令失败 - 给出错误“地址错误”。我已经确认第二个 send() 命令
标记包含 !Send 的类型背后的原因是什么?字段(如 Rc 或 NonNull )与 Send特征?例如,标准库的 LinkedList 以这种方式工作:它包含 Option>字段并实现 Send特
我是新手,我正在尝试学习 goroutines 中信号函数的一些基本用法。我在 go 中有一个无限循环。通过这个 for 循环,我通过 channel 将值传递给 goroutine。 我也有一个阈值
如果数据是从另一台计算机(首先)“发送”的,我如何设置我的套接字例程以“发送”(首先)或(切换)“接收”? 谢谢 通用代码: -(void) TcpClient{ char buffer[12
这个问题已经有答案了: Java multiple file transfer over socket (3 个回答) 已关闭 4 年前。 我正在使用 Java Socket 将文件发送到服务器,然后
根据以下示例中的类型,Go编译器似乎将执行两个完全不同的语义操作: chanA <-chanB 如果chanA是类型(chan chan <-字符串),则此操作会将本身类型chanB的类型(chan
我正在尝试在 VBA 中使用 WinSock2 从本地主机 TCP 流发送(以及稍后接收)数据。 目前,我主要尝试从此处复制客户端示例,https://msdn.microsoft.com/en-us
我在我的 Mac OS X Yosemite 控制台中看到了这个: AppleEvents: Send port for process has no send right, port=( port:
我知道Clojure的“代理”是ref,带有“操作”的添加工作队列。 Action 是使用ref的值在第一个位置调用的函数,可以将其传递给其他参数。操作将返回ref的新值。因此,“代理”是一种计算re
我无法将任何对象或数组传递给 IPCRenderer。 通过 ipcs 传递对象或数组时出现错误,我什至尝试通过使用 JSON.stringify 转换为字符串来发送,但它会将其转换为空对象字符串。
我正在使用unix scoket进行数据传输(SOCK_STREAM模式) 我需要发送超过100k个字符的字符串。首先,我发送一个字符串的长度-它是sizeof(int)个字节。 length = s
Clojure API 将这两个函数描述为: (send a f & args) - Dispatch an action to an agent. Returns the agent immedia
def send_Button(): try: myMsg = "ME: " + text.get() msg = text.get() con
Ruby 对象都有一个“发送”方法,但是,我正在尝试使用一个 Java 库 ( netty-tools ),它的一个接口(interface)上有一个“发送”方法。 用法应该是 java_obj.se
Feb 8, 2011 11:56:49 AM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPC onnection post SEVE
来自 man 2 send: MSG_MORE (since Linux 2.4.4) (…) Since Linux 2.6, this flag is also supported for UDP
我的网页中可以有一个按钮,用于将预填充的消息发送到特定号码吗? 我正在尝试 intent://send/+391234567890#Intent;scheme=smsto;package=com.wh
我是一名优秀的程序员,十分优秀!