PHP automatic email sending function-php Tutorial

Source: Internet
Author: User
PHP automatic mail sending function Click to view full text

Idea: first set the time in the background. after the time is set, the foreground program will be followed.

Step 1: execute the JS code that sets a fixed cookie Time value in ajax.:

/********** Set the start time of the participation here. *** execute the execution once every minute *********/

$. Ajax ({

Url: "ajax. php? Action = time_ajax"

});

/*********** Set the end time of participation **********/

Step 2: Set the cookie value in ajax

Case 'time _ ajax ': // defines the place where execution is performed per minute and a fixed timestamp. this is a fixed cookie that is not affected by refreshing other pages, depends on your situation.

Setcookie ("fasong_time", time (); // record a cookie timestamp

Exit ();

Break;

Step 3: execute the JS code for automatically sending emails:

This step is the js program executed when the page is loaded and will send a request to ajax.

Functionfasong_email (){

$. Ajax ({

Url: "ajax. php? Action = fasong_zidong ",

Success: function (data ){

// Alert (data );

If (! Data) {// if there is a returned value, it will be executed once.

Qwe ();

}

}

});

}

Functionqwe (){

Fasong_email ();

}

Qwe ();

Script

Step 4: execute automatic mail sending

Case 'fasong _ zidong ': // automatically send an email

/*********** Start the Mail sending module *********/

$ Now_time = time (); // Obtain the current timestamp first.

$ One_data = "select 'headers of emails set in the database ', 'Content of emails set in the database ', 'hour field set in the database (this is a numeric field) ', 'minute field set in the database (this is a numeric field )', 'The field set in the database to enable the automatic sending function 'from 'table name "'; // query

// $ One_datas = query function execution $ one_data statement; write your own query statement here

If ($ one_datas ['is _ open']) {// determines whether the Mail sending function is enabled.

If (intval ($ now_time-@ $ _ COOKIE ['fasong _ time']) = intval ($ one_data ['hour field set in the database (this is a numeric field) '] + $ one_data ['minute field set in the database (this is a numeric field)']) {

Require_once ("fasong. php"); // compare the current timestamp with the time length set in the background.

Echo 1;

}

}

/*********** The Mail sending module ends *********/

Exit ();

Break;

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.