Recently a small project need to use the automatic notification function, search, found Phpmailer this thing we use quite a lot of.
First go to sourceforge download Phpmailer, also can go to my network disk download, I use is 5.1 version of.
See the Phpmailer directory with three class files, this is the core of Phpmailer, you can copy these files to your project.
It is convenient to use Phpmailer, as follows:
require("class.phpmailer.php");
$mail = new PHPMailer(); //建立邮件发送类
$mail->CharSet = "GB2312";
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->Port=25;
$mail->Host = "smtp.qq.com"; // 您的企业邮局域名
$mail->Username = "frommail@qq.com"; // 邮局用户名(请填写完整的email地址)
$mail->Password = "213123"; // 邮局密码
$mail->From = "frommail@qq.com"; //邮件发送者email地址
$mail->FromName = "tester";
$address = "tomail@qq.com";//收件地址
$mail->AddAddress("$address", "a");
$mail->Subject = "测试消息通知";
$mail->Body = "您好!系统中有条信息未审核。"; //邮件内容
if(!$mail->Send())
{
echo "邮件发送失败. ";
echo "错误原因: " . $mail->ErrorInfo;
exit;
}
Copy Code
You can call the next database before sending a message to see if a message needs to be sent.
Since our project is running on a Windows server, we need to check periodically to see if we need to send a message. Linux can be easily resolved with crontab under Windows to use the Windows Task Scheduler.
First you need to write a bat script, but the bat script in the execution of the task plan, how to appear a black box, very scary, so write a VBS, through it to call the bat script, bat script to invoke the PHP implementation function.
The VBS contents are as follows:
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c E:\xampp\htdocs\sdc\application\mail\timeSend.bat",vbhide
Copy Code
VBS calls TIMESEND.BAT, which reads as follows:
E:\xampp\php\php.exe E:\xampp\htdocs\sdc\application\mail\mail.php > E:\xampp\htdocs\sdc\application\mail\log.txt
Copy Code
Open task pane, System and security, management tools, planning tasks , create new basic tasks , trigger the time you want to trigger, select Start Program , browse to choose your own VBS program, click Done.
This allows the program to send messages at a specified time.
|