i need a advice, basically i have a multistep wizard form, and in this wizard, for marketing purposes i need to save in the first step (name, email, address) to the database, case the user dont finish all the wizard steps.
But i need to create a email notification to the administrator case the user doesnt finish the form. So what i think was for example in cpanel create a cronjob that verifies in my database for records that doesnt have completed the multistep and than send a email to the administrator with there emails.
But there is a issue, i need to update a column in my records, in my case a column called "verified" that is boolean and when the mail is sent but to true so that every time the cronjob fires up dont send always emails to the administrator.
But it looks like that cronjob only supports Get method, does anybody have a advice?
Request methods (GET, POST, PUT, DELETE, etc.) are HTTP-specific, not CRON jobs.
But it looks like that cronjob only supports GET method
This is wrong. Cron jobs are to call specific file(s) on a specified time interval. You can read it here: Cron Jobs
In your case, you need to following things:
When the form is partially completed, you are saving the data in the
database. So, you can save using 2 columns in the database, 1 is to check the users who have not completed the form and 2nd is to check if the email is already sent to them.
Suppose 2 columns are is_incomplete (to check users who have not
completed the form) and is_followup_email_sent (to check if the email
is sent for further follow ups).
In your CRON file path, you don't need to specify any GET param until
its needed. You just need to call a file placed on your server and in
that file, you need to connect to the database to get users where
is_incomplete = 1 (form not completed) and then make another
function to send email to this list of users and set
is_followup_email_sent = 1 (that means email is already sent)
Whenever your CRON file is called, you just need to make a check at
the top that you get all those users where is_incomplete = 1 and
is_followup_email_sent = 0 i.e. users who have not completed their
form and admin email is not sent to them yet.
I hope this will help you! Cheers.
Request method (Get, post, put,...) is http-specific. When you run your code in the terminal (cronjob) you do not have a request method.
You should create a script (or command depending if you use a framework) that checks everything and changes the value in the database.
Related
I am trying to set up a system where a user enters some information in a form and an email will be constructed where the information is saved into mysql.
I am trying to figure out how to make it so the email will be sent, for example, 20 minutes after the user makes their input. (Without the user staying on the browser).
I need this delay as I need the ability for an admin to log on to a page to look at the email and possibly edit it before it sends.
Is this possible through a cron job. Am I able to set one up that automatically checks sql table for an update and then sends the email after a certain time?
Or is it possible to delay a php script with the sleep function and then send the email. Can I make the PHP script still run when user has closed site and left?
you can use mySQL to store the data sent by the user. this data will be accessed later using another script triggered by a cron Job: if you have the ability to set cron jobs in the control panel or via access to the server, go ahead, use cron tab syntax to define when the job will be triggered, this website may help you:
https://crontab-generator.org/
another approach is to use external service to trigger an event every interval, the event could be accessing the cron job script via HTTP.
if you want your email to be sent exactly after 20 mins, please add a field to your mysql table indicating the desired send date(beware of timezones).
you may also want to add a flag indicating if the email is sent, so you do not send the same email twice.
You can't (easily) have a PHP script stay alive that long.
Your best strategy, IMO, would be to have the PHP script create the email file, and notify the human.
Then you can have PHP run a shell script which uses the "at" program to schedule a task to happen in 20 minutes. At is a cousin of cron, but is better suited for this job.
That scheduled task will be to take the e-mail message, move it some place else (like a "done" directory), and pipe it through your mailer. tip: /usr/sbin/sendmail -t < myEmailFile will work on most Linux boxen.
I am using php and Mysql.
I have a record in my database and i want to check status value of the record after 24hrs of its insertion if it is still in pending or no changed i want to send an SMS and an Email to some person relevant to the status.
To achieve this i have implemented a solution in which i used a php code but it need to continuously execute and check status of record that may cause DoS.
In Another solution i create a trigger but i can't able to send db values as parameter to the php file.
so what should be its solution????
Two ways came into my mind for this.
First, (the good way) using cronjob. It's a really good way.
Second, (bad way for your purpose) Check to see which rows has age of 30 days in each request coming to website. There are cons for this way as the website doesn't get visitors for some days then SMS or Emails won't be sent on time. Another bad thing is it executes on every request so loading time and memory will be consumed during this process.
created a php file which contains a functionality of send sms and email.
then create cronjob:
wget http://example.com/x.php
provide full address of your file.
while creating cronjob set time interval 24hrs
I have a registration form on my site. The form is sent to the server via AJAX and is then validated. Then it will output an address for the browser to be redirected to, if it was validated as valid information. PHP will then send a validation email to the email specified. The problem is that the sending of the email takes 10 seconds, and I don't want my users to wait for 10 seconds from they press Register to they get redirected...
Is there a way for PHP to tell the client the information was correctly validated and output the redirection URL, and continue sending the email without the client waiting?
It's called a background job.
To do this in the simplest way (note: not the best, but the simplest):
I'm assuming you're storing your registration details in some form of database. Add an extra column to flag that you need to send the validation email to this user.
In another script, check the database for any rows with this flag set, and send the email from there.
This second script will be triggered by a cronjob or similar, on a schedule of your choosing.
This way, users don't need to wait for that 10 seconds.
There are more efficient solutions that will cope better for larger scale sites, but I'm guessing that you don't yet need to know this, and that if I brought them into the equation it'd confuse matters. Look into Job Queues, if you want to know more.
I am currently working on a registration based website, and I have the server sending an activation email to the user upon registration. This is all done in PHP so, as you can imagine, I am using the mail() function.
This is all fine and dandy, once the user gets the email and clicks the activation link, the 'active' field that is in the 'Users' table is set to true. Here's the problem though, in the case that a user does not confirm their email address, what am I to do?
I have thought of holding details like the date and time the user registers but I don't know how to proceed with this data. How do I have the server automatically delete the user from the database after a set amount of time?
That's what I think I should be asking, but in all honesty I don't know the usual protocol...
Conclusion: Since Cron is for Unix based servers I've had to pass on it, but I found it very interesting that I could just use the Windows Task Scheduler that is built into Windows. This at least means I can test it on my PC before any server hosting. Thank you all
You should definitely store the date and time that the activation link was sent.
There isn't really a way to tell the server to automatically delete stale user data, but it's easy enough to code up yourself. Assuming you have access to cron on your server, you can set up a cronjob to run (for example) every night at 2am and execute a PHP script that searches the database for users who were sent a link more than X days ago but never confirmed it
i think the solution would be Storing the timestamp while sending the mail.
now run a cron every 15minutes which would check that which values are having timestamp more than 24hrs or any timelimit you want and then delete it from db
Just call in your index.php file the following code. (Why index.php ? - because it is requested every time and can "act" as a cronjob.)
(Just Pseudo Code - might need some tweaks!)
mysql_query("DELETE FROM user WHERE active = 'false' AND registerTime < (NOW-60*60*24*7)")
This will delete all Users which have not been activated within 7 Days.
It's just a concept idea i think you can build on.
You should look into cronjobs that you run daily. Simply put in a field in your database with the time your user registered.
I have a simple user signup form with a checkbox that lets users get a daily email notification if there was activity on any of their projects...much like Stack Overflow has a "Notify xxx#example.com daily of any new answers".
My current thinking to implement this in a LAMP environment is as follows:
In the user database, set a boolean value if the user wishes to receive a daily email.
If there is any project activity, the project gets updated with the current timestamp.
Each night (midnight), a PHP file is executed (likely through a cron job) that scans through the project database to identify which projects had activity that day. For projects with activity, the project owner name is selected and the user table is scanned to check if the user wishes to receive a daily email notification. If yes, add to a recipient list; else, ignore.
Questions / concerns I have that would appreciate some guidance on before I start to implement:
I'm in a shared hosting environment. What precautions do I need to take from being misidentified as spam either by the hosting company or the receiving mail servers?
Do I need to "chunk" out the recipient list (50 emails at a time) and email each group? Is this as simple as putting a sleep(30); between each call to mail()?
I'm using the CodeIgniter framework and will have the cron job call the appropriate function in a controller to run this at midnight. How do I limit calls from only the cron job to prevent some unauthorized user from calling this function from the browser?
Thanks.
If you do change the "From" header in php, make sure you change it to the domain that's hosted on that server. It looks suspicious when mail #a.com is being sent by b.com's servers.
I would send the emails individually foreach ($Users as $User)..., since this allows you to personalize the email contents. Even if you don't need to personalize emails now, you might want to later, and the support for it will already be there when you need it.
First, I would store the script outside of the web root. I'm not sure if CodeIgniter will let you do this, but there is no need for the script to ever be served by Apache. Cron doesn't care where the script is stored. Additionally, I've checked the time when the script is executed. If it's not midnight, then don't blast out the emails. Also, you could keep a log around and also check to make sure the emails haven't already been sent that day before sending.
1) Start with an SPF record and a DKIM if you can that lets mail servers know to expect email from your servers
2) First, you need to put the recipients in the BCC field so that it not each user has the email addresses of 49 other users on your system. One step further is to do each email separately, putting only the recipient in the TO field. This approach also allows your to tailor each email to the user (perhaps putting in "Hi [First name]".
3) Have the cron job something like this
wget http://localhost/send-emails
Then in your script, check $_SERVER and make sure you only allow requests from 127.0.0.1
About the third question: You can either use an .htaccess file to prevent access to that specific page or you can call your script in cron with a command line parameter and check for that variable in $argv.
1) The SPF record is the most important thing. Use the email from the domain so whatever#whatever.com, where whatever.com has the SPF records set correctly.
2) It's always good to throttle email, especially when first starting out. You should check your shared servers policies, which are normally 200-500/hour. Calculate how many seconds that comes to. For example 300/hour is 1 every 12 seconds. After a few weeks of sending good emails, you should be ok to send larger amounts.
3) You can have the cron file outside the webroot or limit access via .htaccess or another method.