I have a service that sends out text to an email entered after x number of days. I want to use cron, but I know that because my PHP script uses variables, this would not work. How can I change my PHP or do anything that would allow me to use cron (or even something else)? I just need something where it will store the emails then send them. I'm really new to PHP, so keep it simple please.
我有一项服务,将文本发送到x天后输入的电子邮件。我想使用cron,但我知道因为我的PHP脚本使用变量,所以这不起作用。如何更改我的PHP或做任何允许我使用cron(甚至其他东西)的东西?我只需要存储电子邮件然后发送它们的东西。我是PHP的新手,所以请保持简单。
Here’s my code:
这是我的代码:
<?php
if(isset($_POST['email']))
{
$headers = "From: Memory Jet <your_company@example.com>\r\n";
$to_visitor = $_POST["email"];
$common_data = $_POST["message"];
mail($to_visitor, "Your Memory", $common_data, $headers);
}
?>
2 个解决方案
#1
2
use argv array to read CLI params - http://php.net/manual/en/features.commandline.usage.php
使用argv数组来读取CLI参数 - http://php.net/manual/en/features.commandline.usage.php
if your script is named /bin/script.php
then if invoked as /bin/script.php xyz
the following:
如果您的脚本名为/bin/script.php,则调用为/bin/script.php xyz时,如下所示:
$email = $argv[1];
will assign 'xyz'
to $email
.
将'xyz'分配给$ email。
just read doc I've provided - there's all you need
刚读过我提供的文档 - 这就是你所需要的
#2
1
if you're wanting to store the data to transmit later, either using a database to store the info or writing it to a file would allow you to retrieve it.
如果您希望存储数据以便稍后传输,则使用数据库存储信息或将其写入文件将允许您检索它。
If you need to potentially edit and manipulate the data later on, I'd recommend using a database.
如果以后需要编辑和操作数据,我建议使用数据库。
I'd also recommend looking at http://www.tizag.com/phpT/ for some good, simple tutorials for PHP that really helped me when I first got going.
我还建议在http://www.tizag.com/phpT/上查看一些优秀,简单的PHP教程,这些教程在我刚开始的时候真正帮助了我。
#1
2
use argv array to read CLI params - http://php.net/manual/en/features.commandline.usage.php
使用argv数组来读取CLI参数 - http://php.net/manual/en/features.commandline.usage.php
if your script is named /bin/script.php
then if invoked as /bin/script.php xyz
the following:
如果您的脚本名为/bin/script.php,则调用为/bin/script.php xyz时,如下所示:
$email = $argv[1];
will assign 'xyz'
to $email
.
将'xyz'分配给$ email。
just read doc I've provided - there's all you need
刚读过我提供的文档 - 这就是你所需要的
#2
1
if you're wanting to store the data to transmit later, either using a database to store the info or writing it to a file would allow you to retrieve it.
如果您希望存储数据以便稍后传输,则使用数据库存储信息或将其写入文件将允许您检索它。
If you need to potentially edit and manipulate the data later on, I'd recommend using a database.
如果以后需要编辑和操作数据,我建议使用数据库。
I'd also recommend looking at http://www.tizag.com/phpT/ for some good, simple tutorials for PHP that really helped me when I first got going.
我还建议在http://www.tizag.com/phpT/上查看一些优秀,简单的PHP教程,这些教程在我刚开始的时候真正帮助了我。