Use Phpmailer automatic Email reminders

Source: Internet
Author: User

Recently a small project need to use the automatic notification function, search, found Phpmailer this thing we use quite a lot of.

  1. First go to sourceforge download Phpmailer, also can go to my network disk download, I use is 5.1 version of.

  2. See the Phpmailer directory with three class files, this is the core of Phpmailer, you can copy these files to your project.

  3. It is convenient to use Phpmailer, as follows:

    1. require("class.phpmailer.php");
    2. $mail = new PHPMailer(); //建立邮件发送类
    3. $mail->CharSet = "GB2312";
    4. $mail->IsSMTP(); // 使用SMTP方式发送
    5. $mail->SMTPAuth = true; // 启用SMTP验证功能
    6. $mail->Port=25;
    7. $mail->Host = "smtp.qq.com"; // 您的企业邮局域名
    8. $mail->Username = "frommail@qq.com"; // 邮局用户名(请填写完整的email地址)
    9. $mail->Password = "213123"; // 邮局密码
    10. $mail->From = "frommail@qq.com"; //邮件发送者email地址
    11. $mail->FromName = "tester";
    12. $address = "tomail@qq.com";//收件地址
    13. $mail->AddAddress("$address", "a");
    14. $mail->Subject = "测试消息通知";
    15. $mail->Body = "您好!系统中有条信息未审核。"; //邮件内容
    16. if(!$mail->Send())
    17. {
    18. echo "邮件发送失败.

      ";

    19. echo "错误原因: " . $mail->ErrorInfo;
    20. exit;
    21. }
    Copy Code
  4. You can call the next database before sending a message to see if a message needs to be sent.

  5. 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.

  6. 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.

  7. The VBS contents are as follows:

    1. Set ws = CreateObject("Wscript.Shell")
    2. ws.run "cmd /c E:\xampp\htdocs\sdc\application\mail\timeSend.bat",vbhide
    Copy Code
  8. VBS calls TIMESEND.BAT, which reads as follows:

    1. E:\xampp\php\php.exe E:\xampp\htdocs\sdc\application\mail\mail.php > E:\xampp\htdocs\sdc\application\mail\log.txt
    Copy Code
  9. 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.

  10. This allows the program to send messages at a specified time.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.