Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Sending An Email

Posted on 2003-03-20
Medium Priority
Last Modified: 2008-03-06
Can i send an email using the mail command, so that the email will
be sent in X time.

i.e user signs up and they pick send my activation email in
X minutes.

I dont want a complicated script or run a cronjob, so if its not possible
i'll take the feature out.

Thanks In Advance...
Question by:tsPHP
  • 2
LVL 15

Accepted Solution

VGR earned 80 total points
ID: 8175545
no, unless you find in the RFC some obscure header for this purpose :D

Expert Comment

ID: 8179392

how about using the 'at' command?  or is this too close as to be called a cron job?

1)  create a two line script named 'emailscript.sh' which looks something like this.  (note, the tmpfile.txt is created in step 2:

/usr/sbin/sendmail -t tmpfile.txt

2)  when user submits form, create the email as a temporary text file tmpfile.txt that looks something like this (obviously replacing recipient with the user's email address):

To: recipient@somedomain.com
From: you@yourdomain.com
Subject: Here's your email

Blah blah blah blah blah blah blah
more blahs
even more blahs

(take note of the last period on the line, this will give a clue to sendmail that this is the end of the file (even though it probably doesn't need that clue. ;) )  Also the blank line between subject and Blah is important.)

3)  after creating the temporary file, now do something like this in your script:

  exec("/usr/bin/at -f emailscript.sh + $minutes minutes");

where $minutes is how many minutes they want to have the email sent.  This could also be + x hours, days, weeks, months, years, etc.  Or even 'at 10am Jul 31'.  Lots of options.  Check out the man page for 'at'.

That wasn't too bad, right?  =)

If you get mass amounts of use, you'll probably need to perform some sort of file locking on file.txt so that multiple scripts don't overwrite it.  Something stupid might be:

  while (file_exists("tmpfile.txt")) {

  // create tmpfile.txt

  // run exec() function


there's much better file locking than this in PHP using flock():


lots of typing for 20 pts. ;)
LVL 15

Expert Comment

ID: 8179421
yes, definitely too close to a cronjob ;-)

Author Comment

ID: 8193814
Sorry for the delay in the reply i was off work..

I am going to award the points to VGR as he did point out
in the first place that i couldn't do it.

Thanks alot for both your answers.


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question