Jump to content

PHP compare date in mysql to sendmail


joshuaer

Recommended Posts

I am fairly new to php and mysql but I have created a small site that users log into and create tasks to be sent to specified email on certain daysThe days are stored in the database as mon tue wed, etc. and I have a column for each day in the database (dont know if that is a good way to do it)The script is will send the information to all the emails in the database when the script is manually.Using cron jobs I will schedule the script to run two times a day to send out each users data to their emails.but I dont know how to tell the script to compare the days the users have specified in the database with the current day to see if it needs to send the email to the users email that daylooking around different sites I found this query that may do what I am wanting but I am not sure how to tell hte script to send out the emails after getting the data from the query select from mailinglist where daytosend = dayofweek(now())Here is my sendmail script, if I run it manually it works correctly and sends out the users data but currently configured does not take into account the days<?phpini_set('display_errors', 1);error_reporting(E_ALL); mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $headers = '';$result = mysql_query("SELECT * FROM users")or die(mysql_error());$row = mysql_fetch_assoc($result);$Cnumber = mysql_result($result,$row,"Cnumber");$address = mysql_result($result,$row,"address");$info1= mysql_result($result,$row,"info1,");$info2= mysql_result($result,$row,"info2");$info3= mysql_result($result,$row,"info3,");$info4= mysql_result($result,$row,"info4");$info5= mysql_result($result,$row,"info5");$txt = "Today's info- "; if(mysql_num_rows($result) > 0) { $count = 0; while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {$message = $txt . $row['info1'].', ' . $row['info2'].', ' . $row['info3'].', ' . $row['info4'].', ' . $row['info5'];$to = $row['Cnumber'] . $row['address']; mail($to, $headers, $message); $count++; } echo "myResult=$count Emails Sent. Done."; print $to;print $message;} else { echo "myResult=Email Submissions Failed."; } ?>

Link to comment
Share on other sites

Thanks for the reply, once it determines the correct day how do I correlate that to tell it to send the email? Not sure how to tell the script that once the days match for current day and what is in the database to send the email Thanks again

Link to comment
Share on other sites

Guest So Called

You run your script every day and look at each entry in the database and skip the ones that are not the appropriate day. You send the emails only when the day matches up.

Link to comment
Share on other sites

Sorry, not to sound like an complete idiot but in the script I put in above, I would run that with a cronjob everyday to have it check the current day against the day in the database. But I really dont understand is when it finds matching data from the curent day and the day set in the database is how it will know to run the sendmail portion of the script. is there a if statment I need to add in there after date function thats say if the days match up run sendmail for the matching columns?

Link to comment
Share on other sites

is there a if statment I need to add in there after date function thats say if the days match up run sendmail for the matching columns?
yes.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...