2

I have a content type in which I have drop down list with the values of "daily" and "weekly" and one field is of email. I want to setup the cron function like when the value of that drop down list is "daily" then email will be send daily to the email address of whatever entered in the email field and when the value is "weekly" then the email will be send weekly.

I don't have any idea about this. How will I do this?

2

How are you generating your email? It sounds to me like you need a custom module that implements hook_cron. It would have to save the email address and send_interval to it's own table (or you'll have to build a query to select the email and interval from wherever you've stored it) in the database during hook_nodeapi with the update $op and/or the insert $op. I recommend creating a 3rd column in your table with a date for the last time email was sent. That way if cron gets interrupted it can continue where it left off. Use a sql query to select all of the rows with column interval == daily and date < NOW() and send emails out. Then do the same if the date is a Sunday or whenever you want to send weekly emails for those. As you process a row, update the date field to the current time which indicates the email was sent.

If you're not up for custom development, you may want to see if the notifications module suites your needs.

  • but how could I code in hook_cron()? As this function can only be declared once in module file and I have two conditions. I did not understand your logic. You mean I have to place two if conditions in the hook_cron() function? like if(value="daily" && date="now() . '12:00:00'"){//send email} if(value="weekly" and day="Monday") {//send email} – Ahmad Sep 8 '11 at 10:04
0

use the module simplenews and schedule your emails, you don't need programming for that or use triggers and input the time as your variable

  • No I have to code in hook_cron(). I don't need any built in module. – Ahmad Sep 8 '11 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.