Link to home
Start Free TrialLog in
Avatar of mmbaba
mmbaba

asked on

should send an email automaticaly when that time come

I would build a php script work as the cron system

it should connect to the database of some dates then if one of those dates = the system date , an email should be send.

this should happing automatically without calling this script through the browser.

to let you suggest a script

let us we have a date saved into the following variable:

$D='2002-10-15' ;
and the email should send to:
$Email='myself@myname.com';
Avatar of VGR
VGR

Well, I personally do this already, so I'll give you my solution, right ?

1) I use a Delphi program ("robot") to access the PHP pages I want to be refreshed on a timely basis (using a Timer in Delphi). This works very well

2) You could also put a refresh of 86400 seconds (24 hours, one day) in a special PHP page always running somewhere in a browser, but this is less reliable. If this runs on the web server itself, this has the advantage of not relying on the actual availability "to the outside world" of the server because then the page would be updated every day on "localhost")

3) you may also use a real crontab entry (if your server is on unix/linux) passing to php.exe in binary CGI mode the correct arguments, but I'm no specialist at that.

I prefer solution 1, althought it's dependent of the status of the actual data line.

--- this enables you to simulate a cron behaviour ---

Now, as for your email sending from PHP.

I recommend this :

If you have an ISP providing you with the mail() function, or a server correctly configured on Windows (sendmail_from, etc in php.ini), then $globEmail would have been set to one. If not, I've an emulation (ersatz) stuff.

if ($globEmail==1) {
  mail("$destinataire", stripslashes($sujet), "$content","From: contact@$SERVER_NAME\nReply-To: contact@$SERVER_NAME\nX-Mailer: PHP/" . phpversion()); // avec extra headers (à voir)
} else { // on pallie
  echo "<FORM NAME=mailform ACTION=\"mailto:$destinataire?Subject=".stripslashes($sujet)."\" method=POST ENCTYPE=\"text/plain\">";
  echo "<input type=hidden name=corps value=\"$content\n\">";
  echo "</FORM>";
  echo "<script>document.mailform.submit();</script>";
} // mél simple ou ersatz compliqué 8-))

I use all of these techniques intensively ; if you really have problems sending email from your target server, then your PHP script may call this page http://www.fecj.org/edain/safeemail.php passing arguments like http://www.fecj.org/edain/safeemail.php?destinataire=....&sujet=....&contenu=...

And it's my server who will send your email ;-)
NB : I could have done a version with attachments, but didn't have the time nor the need ;-) I send only textual attachments, so they can be put in the "contenu" field (body of the message)
NB2 : you may really automate the sending by providing send a value , not forgetting to provide the various hidden fields that you'll find in the FORM source.


Good luck
VGR
www.edainworks.com
Avatar of mmbaba

ASKER

unfortunately, I have a Linux system :-), so I need a way to run your script., perhaps using crontab
then why not solution 2) ? Just hide or minimize the browser window...

As for solution 1, note that this could be running on any Windows machine anywhere on the Net ;-)

If your server is not connected publicly on the Net, you can use "exotic" port number for that HTTP request, or a login/password, or https, or... possibilities are infinite.
Avatar of mmbaba

ASKER

but I need to let the system do that without action from my side, (My machine OFF , Server ON)

I know that this possible but how?
OK

This is not completely possible. The server can only take actions "on its own" using a crontab and such (or scheduled stuff for zindoze)

Personally, I would consider a PHP page open on the server, havinf a proper refresh value, and making the actions take place. That's the simpliest solution and it only requires you to perfom the launch of navigator process+name of page at boot time of the server.
ASKER CERTIFIED SOLUTION
Avatar of ShockwaveRK
ShockwaveRK

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmbaba

ASKER

thanks this what I need, perfect Greetz.
right, that's my solution # 3   ;-))