Tutorial :How can I control the lifetime of an email (time of transmission) with PHP Simple Mail?


I am using Simple Mail from PHP. Now I have the intention of knowing the life time of an email.

If a user wishes to send email one day after submitting the 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?


I don't think there is a way for you to set the delivery date of the message while sending the message.

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

The 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.


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.


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).


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »