Hi All, I have a website hosted at say, abc.com and I have database of registered users with their email id. Now I want to run a logic and get a subset of the users, and send them an email once a month. Something similar to reminder mail. As I see, this task is divided in three sub modules- 1. A PHP script with a logic which will get me that subset of users 2. A sendmail($email_id) kind of function which will do the work of sending mail to given address 3. A way to schedule the execution of PHP script (of module#1) and sendmail function, so that email would be sent once in a month automatically I have module#1 ready but I am stuck with module #2 and #3. I am new to doing mail stuff using PHP, I want to know - what all things/settings I should be knowing to do send mail coding in PHP - I want to send all those reminder emails to users with admin@abc.com as sender , how to achieve that? - Any pointers to start off with this would be of great help When I search on how to go about implementing module#3, I found that CRON is preferred way to implement scheduling. But I enquired to my hosting provider and got to know that It is not accessible to me. So please let me know any other alternate ways to implement the scheduling of a PHP script. Thanks, Ravi
Why on earth wont they give you CRON Jobs? Err well short of triggering the script manually once per month, you could add a conditional statement to a regularly accessed page that runs the script if the date is the first day of the month and the script hasn't already been run in that day. That would obviously only work if there is some script within your main site that is used regularly.
I'm quite surprised too that you can't setup cron scripts, I've never had an issue with that on shared hosting accounts before...? Unless you're on a Windows machine and it works differently? Anyway, email in PHP at it's simplest level can be sent like this: mail("user@email.com", "subject", "text content"); PHP: You'd probably be better using a third party email class since it'll manage all the content, smtp config better. There's loads around, LibMail being a good one - http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en
If cron isn't enabled on your account, you can either 1. Signup with a free hosting provider who support cron and setup a cron using "wget" or "curl" so that the cron will call the file hosted on your main hosting provider or 2. try running the script manually on every month As for sending the email, this simple function will be best You can also make use of advanced mail sending class such as PHPmailer for html format supprt
<?php $to = "j@yahoo.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "admin"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> similar code with out having to use function.
As they said a cronjob on another server is the easiest way besides switching host. (i would do the last one) Anyway if you´re going to call it from another server, don´t forget to password protect it or anyone can trigger it at any time.