jmr3460 Posted June 21, 2009 Share Posted June 21, 2009 I have written a small mailer script that emails a link to an email list. It has no other output very simple. I planned to run it with a cron job. Is there a way to keep the search engines from hitting this file? I fear that if they hit it it will send me the email with the link. I don't want to get three or four emails a day from this mailer. Can I create a Database so that the date and time of the last time the script ran was inserted and only run the mail() it if it has been 7 days later. How could I do that? This is my current script: <?php $to = "[email protected]"; $subject = "Upcoming Events"; $upcoming = "Upcoming Events for the Calendar \n\nhttp://www.xxxxxx.org/activities\n If you can click this link or you may have \nto copy and paste the above line into your browser address bar."; $headers = "From: [email protected]"; mail($to,$subject,$upcoming,$headers); ?> Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/163095-solved-reminder-mailer-file/ Share on other sites More sharing options...
jmr3460 Posted June 21, 2009 Author Share Posted June 21, 2009 This is what I ave come up with so far. Not tested yet. <?php $host = "localhost"; $user = "user"; $pass = "pass"; $table = "mailer"; $database = "mailer"; $date = date("M-d-Y h:i:s", time()); mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); $sql = mysql_query("SELECT date FROM $table WHERE ORDER BY id DESC LIMIT 1"); if ($sql != $date + 604800){ $to = "[email protected]"; $subject = "Upcoming Events"; $upcoming = "Upcoming Events for the Calendar \n\nhttp://www.xxxxxx.org/activities\n If you can click this link or you may have \nto copy and paste the above line into your browser address bar."; $headers = "From: [email protected]"; mail($to,$subject,$upcoming,$headers); mysql_query("INSERT INTO $table VALUES ('id','date')") or die mysql_error(); } else { exit; } ?> With this I am getting my mail but it is not inserting data into the table. Link to comment https://forums.phpfreaks.com/topic/163095-solved-reminder-mailer-file/#findComment-860535 Share on other sites More sharing options...
jmr3460 Posted June 21, 2009 Author Share Posted June 21, 2009 OK this script as is adds a row to the table and sends me mail no matter what time it is. Either my if statement is wrong or my $sql query is wrong. I want to select the last rows time field which is a number in seconds. I only want the run mail() and insert query at the bottom if the Select query is greater that $date +60. This is what I have so far: <?php $host = "localhost"; $user = "user"; $pass = "pass"; $table = "mailer"; $database = "mailer"; $date = time(); mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); $sql = mysql_query("SELECT time FROM $table WHERE ORDER BY id DESC LIMIT 1"); if ($sql >= ($date + 60)){ exit(); }else{ $to = "[email protected]"; $subject = "Upcoming Events"; $upcoming = "Upcoming Events for the Calendar \n\nhttp://www.xxxxxx.org/activities\n If you can click this link or you may have \nto copy and paste the above line into your browser address bar."; $headers = "From: [email protected]"; mail($to,$subject,$upcoming,$headers); mysql_query("INSERT INTO $table VALUES('id','$date')") or die(mysql_error()); } ?> Can someone Please help? Thanks Link to comment https://forums.phpfreaks.com/topic/163095-solved-reminder-mailer-file/#findComment-860562 Share on other sites More sharing options...
jmr3460 Posted June 21, 2009 Author Share Posted June 21, 2009 Ok this is what I am getting now. I think I have my $sql query wrong. this is my warning: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/arscnaor/public_html/mailer.php on line 15 I think that line $sql is not getting the number since my result resource is not valid. My $table is setup with two fields id int(5) auto_increment and time int(11). I used int so I could do the math thing to compare my two variables. Here is my new code: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = "localhost"; $user = "user"; $pass = "password"; $table = "mailer"; $database = "mailer"; //sets date in seconds to be inserted into Db till next cron job runs $date = time(); mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); //I want to find the last entry of time in my $table $sql = mysql_query("SELECT * FROM $table WHERE ORDER BY id DESC LIMIT 1"); $info = mysql_fetch_array($sql[time]); //creates a new variable to compare with last time entry of $table //(+ 60 will be changed to equal 1 week once the script is working) $result = ($info + 60); $newdate = time(); //I am trying to compair my two times and if $newdate if ($newdate < $result){ exit(); }else{ $to = "[email protected]"; $subject = "Upcoming Events"; $upcoming = "Upcoming Events for the Calendar \n\nhttp://www.xxxxxx.org/activities\n If you can click this link or you may have \nto copy and paste the above line into your browser address bar."; $headers = "From: [email protected]"; mail($to,$subject,$upcoming,$headers); mysql_query("INSERT INTO $table VALUES('id','$date')") or die(mysql_error()); } ?> <html><body> <?php echo $newdate . "<br />"; echo $result; ?> </body></html> Is my $sql query a good query? Link to comment https://forums.phpfreaks.com/topic/163095-solved-reminder-mailer-file/#findComment-860723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.