views:

154

answers:

4

Hi, I want to a e-cards or something like that. The user can choose the e-cards, after chosen, he must enter the some fields like name(to and from), email(to and from), message and I want to let user to choose which date to send the e-cards.

How to send the e-cards on specific day? I need to write a script that run every new day? How to do that? Sorry, I am new to php... (but not beginner like not even know how to execute mysql query, get message from url etc)

+9  A: 

Yes, you need a script that runs every day. (Barring ridiculous maneuvers like trying to fake this by checking on Web requests.) The usual way to do this in a Unix context is called a cron job; if your hosting provider is Unix-based, you should look into what they provide for making cron jobs available to you. On Windows there's a parallel service called Scheduled Tasks.

chaos
+1 for covering 2 platforms
alex
A: 

This is somehow complex. First it depends on your system. If it is Linux/BSD/Unix/Solaris then you have this handy utility as cron. If you are using Windows, you have Scheduled Tasks. Run your script daily (or as you wish) and check what cards you have to send today.

Pavels
+1  A: 

This is for *nix. Let's say you have a php script that sends email on a specific day called mailer.php

<?php
    //mailer.php
    if (date("m/d/Y") == "06/02/2009") {
        mail("client@email", "Subject", "Body");
    }
?>

We are going to assume that you already have cron daemon running in the background.

If you have root access to your machine, then setting up a cron job is simple as editing a file.

Open up /etc/crontab file and add the following task:

1 14 * * * root php /path/to/your/scrip/mailer.php

This means, as a root, the mailer.php script will be ran daily at 02:01PM. You can change the numbers to whatever you desire.

Highwind
+1  A: 

A similar question was disscussed here resetting-a-mysql-field-value-without-user-execution

I'll just reiterate: There are web based cron services too. This could come in handy if you only got a shared hosting plan and can't add cron jobs. They will call an URL at a regular interval that you can set. Usually very cheap. (Cheaper than upgrading to a root-access server anyway.)

Just search Google for web based cron

ciao! /0

0scar