Use phpmailer for automatic email notification

Source: Internet
Author: User
Use phpmailer for automatic email notification
In a recent small project, you need to use the mail automatic notification function. after searching, we found that phpmailer is a lot of things.
  1. First, go to sourceforge to download phpmailer, or go to my online storage. I use version 5.1.

  2. The phpmailer directory contains three class files, which are the core of phpmailer. you can copy these files to your project.

  3. Phpmailer is easy to use, as follows:

    1. require("class.phpmailer.php");
    2. $ Mail = new PHPMailer (); // Create a mail sending class
    3. $mail->CharSet = "GB2312";
    4. $ Mail-> IsSMTP (); // send using SMTP
    5. $ Mail-> SMTPAuth = true; // enable SMTP verification
    6. $mail->Port=25;
    7. $ Mail-> Host = "smtp.qq.com"; // your enterprise Post Office domain name
    8. $ Mail-> Username = "frommail@qq.com"; // Post Office Username (enter the complete email address)
    9. $ Mail-> Password = "213123"; // Post Office Password
    10. $ Mail-> From = "frommail@qq.com"; // email address of the sender
    11. $mail->FromName = "tester";
    12. $ Address = "tomail@qq.com"; // recipient address
    13. $mail->AddAddress("$address", "a");
    14. $ Mail-> Subject = "test message notification ";
    15. $ Mail-> Body = "Hello! Information in the system is not reviewed. "; // Email content
    16. if(!$mail->Send())
    17. {
    18. Echo "failed to send the email.

      ";

    19. Echo "error cause:". $ mail-> ErrorInfo;
    20. exit;
    21. }

  4. You can call the database before sending a message to check whether a message needs to be sent.

  5. Because our project runs on a windows Server, we need to regularly check whether emails need to be sent. In Linux, you can use crontab to easily solve the problem. in Windows, you need to use the windows task plan.

  6. First, you need to write a bat script, but how does a black box appear when the bat script executes the task plan? it is quite scary. Therefore, first write a vbs and use it to call the bat script, the bat script then calls the php implementation function.

  7. The vbs content is as follows:

    1. Set ws = CreateObject("Wscript.Shell")
    2. ws.run "cmd /c E:\xampp\htdocs\sdc\application\mail\timeSend.bat",vbhide

  8. Vbs calls timeSend. bat. the content is as follows:

    1. E:\xampp\php\php.exe E:\xampp\htdocs\sdc\application\mail\mail.php > E:\xampp\htdocs\sdc\application\mail\log.txt

  9. OpenTask panel-> System and Security-> Management Tools-> schedule tasks, NewBasic Task, The time when the trigger wants to be triggered, and select the operationStart the program, Browse and select your own vbs program, and click finish.

  10. In this way, the program can send emails 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.