Jump to content

How to import table in database into cron jobs in c-panel so emails can scheduled?


I-T

Recommended Posts

Ok this is my issueCurrently I have a specific table in my database that holds all the email addresses that i send an email to.The 200 bulk emails gets sent by going into the CMS(content management system).In the database their is a field called active_field and by default all set to 0. I only turn them to 1 when the 200 emails are ready to be sent. This method takes too long seeing that I send 200 bulks of email about an hour or abit longer and I manually have to re run the query to set the ones I already sent back to active_flag 0 and grab a whole new 200 and set them to active_flag 1. I did research on cron and I belive you can schedule it to send the bulk email every hour but I dont know how to use it or where to start. or maybe use some sort of a trigger method on mysql phpadmin to set the active_flags to 1 when the 1 hour time is up??Any ideas or solutions would be highly appreciated. thanks

Link to comment
Share on other sites

You can use a cron job to run any PHP script you want. I have an email script that runs every minute to see if there are new emails in the queue waiting to go out. It will process as many emails as there are to go out and run as long as it takes to finish the work, so I needed another way to keep track of whether that script was currently running so that the next time the script starts after the next minute it doesn't try to send the same emails. But you can schedule any PHP script you want to run on a schedule using cron, it's not special code or anything.

  • Like 1
Link to comment
Share on other sites

Ok so in c-panel I would click the cron icon. I belive it gives you a step by step process to make a cron-tab which I belive is the php script it will create? Once thats done how do I make it grab the 200 emails from my database that are set to active_flag 1 for it to send?

Link to comment
Share on other sites

It doesn't create a PHP script, you tell it to run PHP and you tell PHP which script you want to run, e.g.: php -f /home/public_html/cron.php You give cron a command to run, in this case you're telling it to execute the php program and then you tell PHP which script you want it to execute. More information about running PHP from a command line here: http://www.php.net/manual/en/features.commandline.php Note that running PHP on a command line is different than running it on a web server. Things that only make sense in a web server, like cookies, sessions, post and get data, the $_SERVER array, etc, are not available in a command line script.

Once thats done how do I make it grab the 200 emails from my database that are set to active_flag 1 for it to send?
It's just normal PHP code, you connect to your database like normal and select your data, loop through the records and send each email. There's information about using PHP to connect to MySQL here: http://php.net/mysqli_queryhttp://forum.codecall.net/topic/44392-php-5-mysqli-prepared-statements/http://www.codeofaninja.com/2012/01/phpmysqli-crud-tutorial.htmlhttp://mattbango.com/notebook/web-development/prepared-statements-in-php-and-mysqli/ I would ignore the w3schools tutorials about PHP and MySQL, that information has been out of date for years.
  • Like 1
Link to comment
Share on other sites

I really appreaciate your responses but bare with me plz.This is the full scale of what I'm trying to do. Firstly I want to run an event scheduler in mysql so that on 9:00AM the active flag field for the 1st 200 emails would be set to 1, then at 10:30AM have another event to set them back to 0, and at that very exact time have another event for the whole new 200 batches set to 1. then so on and so fourth till like 5.00PM I figured out the sql query to do this. Now that in mind I understand that I could simply create a cron job by going into c-panel and accesing the cron icon. It gives me the option to set a crontab which is by picking the times and dates, and also you would see the command box which as you mentiond would require for me to enter something like this "php -f /home/public_html/cron.php" so that it would run my php script that I created. Ok now ofcourse I havent created such a script. Could you give me some sort of a script example where it would grab the emails from my database within a certain table which hold all the emails and ultimately who are only set to 1 in active_flag field. Just to mention I would set the event scheduler and the cron tab to similar times so that it will flow nicely.

Link to comment
Share on other sites

So I would be adding that select statement to my phpscript? if so Why do I need to loop it if its only going to retrieve the emails who are only set to active_flag =1

Link to comment
Share on other sites

yes it will be in your php script.you need to use loop cause it is possible that there is more than one row who has active_flag set to 1

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...