tags:

views:

65

answers:

4

I am using Simple Mail from PHP.

Now I had intention of knowing life time of email.

If a user wishes to send email one day after submitting form, how can I achieve this in PHP?

$headers =  'From: '.$Name.''. "\r\n" .
    'Reply-To: '.$_POST['email'].'' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$subject = "Subject";
$message = "Message";    
mail($to, $subject, $message, $headers);

Is there a header I need to include?

+2  A: 

What you would do is specify the time to send the email. Save that with the email to, subject, message and headers in a database.

Then create a cronjob that checks the database every few minutes to see if any emails are supposed to be sent. If so, that PHP file (that the cronjob executes) will send the email.

Ólafur Waage
A: 

Probably you should store your e-mails in database. Then you can send e-mails by some kind of periodic script (cron, etc.).

Petr Svoboda
+1  A: 

I dont think there is a way for you set it delivery date of the message while sending the message.

You can save the email message in a database and run a cron job everyday to check for emails that has to be sent that day and send them.

Life time of the email is different for example if you have sent an email and for some reason if the message was not delivered, it will queued. And the server will try to deliver the message after some time and still if it is not able to deliver the message the server will delete the email

Shoban
+1  A: 

As others have said, you'll want to put the mail into a database, and then send from there. The Pear Mail_Queue is very easy to use, and you can run the sending process at will, or better, via some cron job (or keep it running, with some 'sleep(10)'s if you want to send it almost as soon as the time has been reached).

Alister Bulman