How to schedule an email autoresponder with cPanel
Level of skill required: a little php knowledge, access to your server via FTP
You can't do it directly from cPanel, but cPanel saves autoresponder info in a way that you can modify via PHP and CRON.
How to do a weekly autoresponder:
This is what I need - I have a rest day every Tuesday, and it's helpful for people emailing me to know that they're not getting an answer for a day!
I don't want to have to go into cPanel every week and setup the autoresponder again, so this little script automates it for me.
1. Set up your autoresponder using cPanel as usual
cPanel > Email > Autoresponders
Choose "Add Autoresponder"
Fill in your details.
The "interval" is neat - supposing Greg emails you every 10 minutes, well you can either send him an Auto-response to every email (set interval to 0, zero), or choose to send every, say, 12 hours. That way he won't get bombarded.
At the bottom of that page, set the dates and times for the next Autoresponder day, and "Create/Modify":
Great, now you've got ONE Autoresponder for next week.
2. Find the Autoresponder data on your server
It's in your username root, in a folder called ".autorespond".
So on my server, it would be /home/myusername/.autorespond
Each autoresponder has two files, using the name of the email associated with the responder:
firstname.lastname@example.org and email@example.com
firstname.lastname@example.org contains the text of the responder message, and email@example.com is what we want to modify.
3. Write a little PHP file to change the Autoresponder data
The .json file is in this format:
That's a UNIX timestamp for start and stop times, and the seconds value of the interval (12 hours in my case)
The timestamps are in GMT for me (and that's my timezone), but how that works with your timezone you'll have to investigate.
So here's a little PHP to set the start and stop times for "Next Tuesday":
<?php // day_off_autoresponder.php define('AUTOR_FILE', '/firstname.lastname@example.org'); // do this so that we get the right GMT time: date_default_timezone_set('UTC'); // get the midnight times we want $nextTuesday = strtotime("next tuesday"); $nextWednesday = strtotime("next wednesday"); // make an array $autoR = array( 'start' => $nextTuesday, 'stop' => $nextWednesday, 'interval' => 43200 ); // and encode it $json = json_encode($autoR); // save it to the file file_put_contents(AUTOR_FILE, $json); echo "Autoresponder file written:\n$json\n" . AUTOR_FILE; ?>
Edit that for your day off, and your email address and server username (and path maybe), and save it as "day_off_autoresponder.php" or something, in your public_html folder, or somewhere else more secure.
4. Set up a weekly CRON job to call your PHP script
Use cPanel again for this.
Choose "Once per week" and an appropriate day before your day off.
For the Command, use:
or wherever you saved it.
And that's it.
You can test if it works by setting the cron to "Every minute", waiting for the timestamp to change on the .json file (watch it with your FTP client) and then visit the cPanel Autoresponder page to see what times are set for your autoresponder.
This is great and I would love to edit this if I knew what I was doing. I made the autoresponder in cPanel to start a certain day at 6:00pm and end at 9:30am the next morning. I would love to have this and weekends configured for the autoresponder. Is there any way you could help me?