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;