通过php脚本定期发送电子邮件

编程入门 行业动态 更新时间:2024-10-09 18:25:08
本文介绍了通过php脚本定期发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个自动监视系统.我已经制作了一个具有MySQL数据库的.NET应用程序.为此,我开发了一个普通的ADMIN面板,管理员可以在其中登录并从数据库中触发的各种查询中获取必要的报告.面板中还有一个摘要报告",只是每周的摘要.现在我想要的是,我希望此报告(所有文本)在7天的时间内自动发送到某些电子邮件"xxxxx@xxx".以前,我曾使用一些PHP脚本在单击提交"按钮时发送电子邮件.像下面的那个.

I am working on an automatic monitoring system. I have made a .NET application which have MySQL database. For this I developed a normal ADMIN Panel where admin can log in and get necessary reports coming from various queries fired on the database. There is also a "summary Report" in the panel which is just the rough weekly summary. Now What I want is, I want this report (all text) to get sent automatically to some email "xxxxx@xxx" with a seven day period. I have used some PHP scripts previously to send email on submit button click. Like the one below.

<?php if(isset($_POST['isPost'])) { $header="From:".$_POST['customer_mail']."\r\nName:".$_POST['name']."\r\nCity:".$_PO ST['city']; $subject = $_POST['title']; $message="From:$_POST[customer_mail]\r\nName:$_POST[name]\r\nPhone:$_POST[city]\r\n \r\n\r\n\r\n".$_POST['details']; $to = 'xxxxxxxxx@xxx'; $send_contact=mail($to,$subject,$message,$header); if($send_contact) { echo "<h6 style='text-align:center;color:green'>Sent Successfully</h6>"; } else { echo "<h6 style='color:red'>Error sending e-mail'</h6>"; } } ?>

这是正常的邮件发送脚本,可以正常工作.但是出于上述目的,有人可以帮助我定期自动设置此操作,也可以为我指明正确的操作方法.我已经谷歌搜索这样的PHP脚本,但没有满意的结果. 〜问候

this is normal mail sending script which works fine. But for the above purpose I want, Can anyone help me to set this action periodically and automatically or point me in the right direction on how to do this. I have googled for such php script but no satisfied results. ~ Regards

推荐答案

您可以使用cronjobs进行此操作. 一个长期运行的过程,可以在给定的时间/日期/间隔执行命令.

You can do this with cronjobs. A long running process which executes commands at given times / dates / intervals.

根据您使用的系统,有不同的方法.

Depending on what system you are, there are different methods.

如果您将脚本放在网络服务器上,则有人正在为您运行/Webhost服务

要求系统管理员使用cronjob运行脚本.或搜索任何帮助文档(如果您可以在任何管理面板中自行设置).向您的网站托管服务商/系统管理员咨询以获取更多信息.

Ask the system administrator to run the script with a cronjob. Or search for any help documentation if you can setup this yourself in any admin-panel. Ask your webhoster /system admin for more information.

如果脚本在您自己的本地计算机上:

UNIX

尝试阅读有关如何运行php脚本或任何脚本的 crontab 的信息对于这个问题.

Try reading about crontab on how to run the php script, or any script for that matter.

例如,键入crontab -e并在crontab中添加以下行,cronjob将每小时运行一次脚本:

For example type crontab -e and add the line below in your crontab, the cronjob will run your script every hour:

00 * * * * /usr/local/bin/php /home/Low-pointer/myscript.php

如果您想间隔学习,这里有一些更多信息

Windows

如果您使用Windows,则可以使用预定的任务来运行php命令.

If you use Windows you can use scheduled tasks to run the php command.

例如,将以下命令添加到调度程序:C:\wamp\bin\php\php.exe -f C:\wamp\www\my_script.php

For example add the following command to the scheduler: C:\wamp\bin\php\php.exe -f C:\wamp\www\my_script.php

您还可以使用Web Cron服务( Google it )这些在线服务会在指定的时间运行页面(例如,在您的网络服务器上).免费或付费.

You can also use web cron services (Google it) these are online services which run a page (for example on your webserver) on designated times. For free or paid.

更多推荐

通过php脚本定期发送电子邮件

本文发布于:2023-10-12 16:16:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   发送电子邮件   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!