?
Solved

Sending An Email

Posted on 2003-03-20
4
Medium Priority
?
219 Views
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...
0
Comment
Question by:tsPHP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Accepted Solution

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

Expert Comment

by:bobsledbob
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:

#!/bin/bash
/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:

<?php
  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:

<?php
  while (file_exists("tmpfile.txt")) {
    sleep(1);
  }

  // create tmpfile.txt

  // run exec() function

  unlink("tmpfile.txt");
?>

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

http://www.php.net/manual/en/function.flock.php

lots of typing for 20 pts. ;)
0
 
LVL 15

Expert Comment

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

Author Comment

by:tsPHP
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.

0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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