bravogila Posted August 4, 2007 Share Posted August 4, 2007 Hi everybody! I am a noob in PHP. Hope someone out there can help me out here. Thanks! Situation -------- - I am modding a simple program that interacts with a MYSQL database which tracks the Expiry Dates of vehicle road licenses. I would like to have the program automatically sent an email warning out to a list of email recipients 30 days or X no. of days before the expiry date of each vehicle's road license - and also perhaps make it possible for the user to be able to define how many days before an expiry date that he/she wants the program send an email alert/warning out. - and there are multiple versions of predefined email text that is system-selected to form the email body when a particular event is triggered - the email body will also contain some other data from that DB record. For e.g. road license no., licensing agent's name,..etc. Help needed ----------- 1. what is the code to use that can help me make the system to check a DB table and retrieve the expiry dates and compare that to a system date.And if today's system date is X no. of days before the expiry date - the system will send out an email warning informing the recipents that he/she needs to renew the license of a vehicle. Like described in the paragraph above. 2. Does PHP come with an in-built email function? How do I trigger it and use it? 3. and whatever other advice you have that can help me to even improve the above described situation....e.g. to make the system able to inform us when a license has been renewed....or whatever you can think of. Thanks lots for your help guys! Quote Link to comment https://forums.phpfreaks.com/topic/63294-how-to-automaticaly-send-an-emailwith-db-data-when-an-event-is-triggered/ Share on other sites More sharing options...
bravogila Posted August 4, 2007 Author Share Posted August 4, 2007 After reading again my post i realised I might not be making much sense at all. It reads like as if I'm asking someone to code the whole thing for me! Sorry...i'm a new noob in programming just have some basic understanding of logic only...actually my question is really... How do I take a field value from a database table and compare that value with the system's date, and run an if-else to it, and if a condition is satisfied - to trigger an email send out? I'm looking for advice on which php code i should use in the following scenarios. I will later check up the proper usage and syntax of those codes on my own:- 1) retrieve field data from a database table 2) take that data and compare with the system generated date. 3) if a certain condition is met, then trigger phpmailer 4) phpmailer intelligent enough to send out email and its correspoding preformated email body Thanks again guys! Quote Link to comment https://forums.phpfreaks.com/topic/63294-how-to-automaticaly-send-an-emailwith-db-data-when-an-event-is-triggered/#findComment-315443 Share on other sites More sharing options...
BipolarChucker Posted August 4, 2007 Share Posted August 4, 2007 I suspect that the reason you haven't had a reply is because most of what you're asking is quite basic. You know the pseudo code to use because you've detailed it in your second post. I admit, not everyone knows all the functions available to use and which is best to use where but a little scouring of php.net would do you good. 1. mysql_connect(), mysql_query(), mysql_fetch() and mysql_result() will work for this particular part. 2. date() will give you the current date but you'll need to convert it in to a format that you can compare to 1. 3. Here I would use a switch() in combination with some additional MySQL fetching to pull out the appropriate email body from a database table that you want to send. 4. mail() is the built in php command to send email. It's quite powerful and can be used for HTML and plain text. Your biggest issue is scheduling the running of the script to achieve the desired results. Obviously it will need running each day to do the comparison. Quote Link to comment https://forums.phpfreaks.com/topic/63294-how-to-automaticaly-send-an-emailwith-db-data-when-an-event-is-triggered/#findComment-315494 Share on other sites More sharing options...
bravogila Posted August 6, 2007 Author Share Posted August 6, 2007 Thanks for pointing me in the right direction, man. Really appreciate it! I have not touched programming for 15 years and I am trying to pick it up again. All I ever did was some QBASIC way back in the early 90's. Appreciate the pointers, it is going to be a great help, thanks again dude! Btw, what are your thoughts on the scheduling of the running of the script to the comparison. Any nifty code tricks available with today's generation of language? Quote Link to comment https://forums.phpfreaks.com/topic/63294-how-to-automaticaly-send-an-emailwith-db-data-when-an-event-is-triggered/#findComment-316872 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.