Jump to content
xisto Community
alex1985

Sending E-mails Based On Intervals?

Recommended Posts

Again, I need your help. I have two database entries, let's say "reg_users" and "news". The question is that if somethings was changed in the "news" database, the email letter will be sent automatically to all emails which are related to "reg-users" database. So, how can I accomplish this point. How can I set this process based on daily, weekly or monthly basis?

Share this post


Link to post
Share on other sites

I have two database entries, let's say "reg_users" and "news". The question is that if somethings was changed in the "news" database, the email letter will be sent automatically to all emails which are related to "reg-users" database. So, how can I accomplish this point.

Simply add the code to send the emails after the code which updates the database. That way, after the database is updated, the emails will be sent.

How can I set this process based on daily, weekly or monthly basis?

Presumably you mean you want to send out a daily/weekly/monthly list of what has changed? You would need to store the time each news item was last edited in the database. Then write a script that looks for news items edited in the last day/week/month and send out an email with a list of them in it.

To make your script run daily/weekly/monthly, look at cron jobs. Google has plenty of tutorials on getting them working, along with tutorials here on Xisto.

Share this post


Link to post
Share on other sites

No offence Alex but your going way out of your depth, your thinking too big, start of smaller, do one bit at a time, stop throwing all these "Help Me" posts out and concentrate on one thing rather than piling your plate up with food but cannot eat it all, take it one step at a time rather than plunging in! Not that I mean don't ask for help, you should, you shouldn't have to work it all on your own however, It would be better saying what you want to do , breaking it down in to snippits of code, i.e if, else here and a php require there, and if you get stuck there's always Xisto

Edited by kobra500 (see edit history)

Share this post


Link to post
Share on other sites

I couldn't agree more with kobra's post. You are acting like the code to do this is just some magical function that we are all keeping away from you. I'm sorry but the function send_email_based_on_database($database) doesn't exist! There is also no magical code that we can give you to do this, well I suppose we could but it would be long and not help you at all. You need to first figure out how php works and what it can do for you. You should have figured out by yourself that rvalkass's post would be most efficient, or at least figure out another solution that would work, for example making another database mirror the first database and make a cron job to find differences between them every day/week/month. And then from there you would be able to patch together the small parts of the project for example "How to go about mirroring the database?" well that would be a bit better of a question to ask us, however you should be able to figure out how to do that as well if you know loops. Then comparing the two databases shouldn't be too hard either. Just go row by row and compare the data. Now don't tell me that you are so thick that you couldn't figure that out. If you take a moment to think about the project you want to do you might actually learn something instead of asking us for code that could be implemented in many different ways.

Edited by galexcd (see edit history)

Share this post


Link to post
Share on other sites

Again, I need your help.

 

I have two database entries, let's say "reg_users" and "news". The question is that if somethings was changed in the "news" database, the email letter will be sent automatically to all emails which are related to "reg-users" database. So, how can I accomplish this point.

 

How can I set this process based on daily, weekly or monthly basis?


Go to the line that you have inserted a new entry into news:

@mysql_query("INSERT INTO news VALUES ('',........//After this, we must select all members who wants to be informed from reg_users	$querymemberstoinform = @mysql_query("SELECT * FROM reg_users WHERE inform_me='1'",$myconnection); 		//You didn't give the structure of reg_users, so think that there is a coulomb inform_me, and who has the value=1 will be informed.	if (mysql_num_rows($querymemberstoinform )>0) {		while ($rsmembers=mysql_fetch_array($querymemberstoinform )) {			if (eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $rsmembers["email"])) { [i]//we check here if the email address is correct.[/i]				$extra="From: Here_write_your_from_name <Here_write_your_from_mail@yourdomain.com> \r\n";				$extra.="Bcc: if_you_want_to_get_a_bbc_copy@youremailaddress.com \r\n";				$extra.="Reply-To: reply_to_name <noreply@yourdomain.com> \r\n";				//$extra.="X-Priority: 1 \r\n"; //if you want to set priority also use here.				$extra.="MIME-Version: 1.0 \r\nContent-type: text/html; charset=iso-8859-9 \r\n";				$mailbody="Dear ".$rsmembers["username"]. ", a news has just been added.<br> <a href=\"your_url_to_the_new\">Click here to read the news</a><br> Or content is here:<hr>".$thecontentofthenews."<hr>";				$mailbody.="Information Systems by alex1985;)";				@mail ($rsmembers["email"], $titleofthenews." titled a news has been added", stripslashes($mailbody), "$extra");			}		}}
I have used @ character before all functions only in sending mail. Because if there is an error occurs, anything about error will not be displayed.

 

By the way to send daily, weekly, or monthly: You can use cronjob. But you must write these codes into a new blank php file and before these codes you must run a query which selects the news rows the last 24 hours, last 7 days, last 30 days.

Good luck.

//Edit: [ b ] and [ i ] bbcodes are working in Code tags, and I have deleted only those.

 

 

Notice from rvalkass:
Code needs Code tags around it.

Edited by Erdemir (see edit history)

Share this post


Link to post
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...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.