954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help sending email at a future date using php

hi, i'm a newbie to php and i'm building a website right now. i giving the users the option to create and send
news letters. i also want to give them the option of sending the newsletters at a later date i.e they can create the newsletters, choose a date and time they would like to have it sent, and then save it, so that at the said time, the mail would be automatically sent.
can anyone help me out with this?
i heard about cron, but it seems its just for unix users and it seems kind of complicated. does anyone have a simpler/better alternative?

cali_dotcom
Junior Poster in Training
53 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

Hi,
I have one simple idea. Store your prescribed date and time in a php variable. Then get system data and time in another variable.
Now, check the condition if system date and time is equal to prescribed date and time, if it is ok then send email else dont send your email. Am i right?

ashafaaiz
Newbie Poster
22 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

unless your site has a constant consistent flow of traffic, cron (nix) / Task Scheduler (windows) would be the only way to accurately do this.

On windows you would need to use the task scheduler. http://www.sugarcrm.com/wiki/index.php?title=Scheduling_cron.php_to_run_on_Windows%2C_Linux_or_Mac_OS_X
This is specific to SugarCRM's setup, but the concept is really easy and you should be able to figure it out.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 
<?php
if (date('j, n, Y') == '10, 3, 2009') {
  mail('mail@example.com', 'Subject', 'Message');
}
?>


Ive not tested it but it should work :)

!Unreal
Junior Poster
112 posts since Dec 2007
Reputation Points: 11
Solved Threads: 2
 

That is a perfectly fine solution, but unless there is someone visiting that page on that date at a certain time, there is no way to force it to be sent:
user creates the email
user schedules it for 01/10/2009 @ 15:00:00
user exits
no new visitors till 01/13/2009
email doesnt send till earliest 01/13/2009

With cron or task scheduler this is avoided.
Just call a script that calls up all the pending emails and sends anything older than the current time.
Depending on how frequently cron is running, every minute, every 10 minutes, etc would be the longest a user would have to wait for their email to get picked up by the system.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You