Home  >  Article  >  Backend Development  >  Automatic email reminder using phpmailer

Automatic email reminder using phpmailer

WBOY
WBOYOriginal
2016-07-25 09:13:101304browse

In a recent small project, I need to use the automatic email notification function. After searching, I found that phpmailer is used a lot.

  1. First go to sourceforge to download phpmailer, or you can go to my network disk to download it. I am using version 5.1.

  2. See that there are three class files in the phpmailer directory. This is the core of phpmailer. You can copy these files to your project.

  3. It is very convenient to use phpmailer, as follows:

    1. require("class.phpmailer.php"); </li> <li>$mail = new PHPMailer(); //Create a mail sending class</li> <li>$mail->CharSet = "GB2312"; </li> <li>$mail- >IsSMTP(); // Use SMTP to send </li> <li>$mail->SMTPAuth = true; // Enable SMTP authentication function </li> <li>$mail->Port=25; </li> <li>$mail->Host = "smtp.qq .com"; // Your business post office domain name </li> <li>$mail->Username = "frommail@qq.com"; // Post office user name (please fill in the complete email address) </li> <li>$mail->Password = "213123 "; //Post office password</li> <li>$mail->From = "frommail@qq.com"; //Email address of the email sender</li> <li>$mail->FromName = "tester";</li> <li>$address = "tomail@qq. com";//Receive address</li> <li>$mail->AddAddress("$address", "a");</li> <li>$mail->Subject = "Test message notification";</li> <li>$mail->Body = "You OK! There is a message in the system that has not been reviewed. "; //Email content</li> <li>if(!$mail->Send())</li> <li>{</li> <li> echo "Failed to send email. <p>";</li> <li> echo "Error reason: " . $mail->ErrorInfo;</li> <li> exit;</li> <li>}</li> <li>
    Copy code
  4. You can call the database before sending the message to check whether there is any message that needs to be sent.

  5. Since our project is run on a Windows server, we need to check regularly whether we need to send emails. It can be easily solved using crontab under Linux, and Windows Task Scheduler under Windows.

  6. First of all, you need to write a bat script, but when the bat script executes the task plan, a black box appears, which is quite scary, so first write a vbs, use it to call the bat script, and then the bat script calls php to implement the function.

  7. vbs content is as follows:

    1. Set ws = CreateObject("Wscript.Shell") </li> <li>ws.run "cmd /c E:xampphtdocssdcapplicationmailtimeSend.bat",vbhide</li> <li>
    Copy code
  8. vbs calls timeSend.bat, the content is as follows:

    1. E:xamppphpphp.exe E:xampphtdocssdcapplicationmailmail.php >
    Open the
    Task Panel->System and Security->Management Tools->Scheduled Tasks, create a new Basic Task
    , set the time you want to trigger the trigger, select
  9. Start Program
  10. , browse and select your own vbs program, Click Done.

    In this way, the program can send emails at the specified time.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn