Solved

Sending mail automatically.

Posted on 2001-06-05
5
215 Views
Last Modified: 2008-03-17
Currently on my website i'm using PHP and MySQL.  What I would like to do is have sendmail on my Linux server send out mails automatically according to a date stored in MySQL.

For example.

Activity: Baseball
Date: June 24, 2001

When the day rolls around to June 24, my PHP script will email out to everyone of the above activity.  It should be all automated and nothing done after initial entry.  I guess the problem i'm having is: how do I build my PHP script so it runs in the background and only sends once.  I'm not sure if this is PHP / MySQL issue OR if it's a sendmail issue.

Can anyone help me shed some light on this?

Thanks,
myuen
0
Comment
Question by:myuen
5 Comments
 
LVL 4

Expert Comment

by:ykf2000
Comment Utility
Hi,

What you can do is to use crontab and schedule to trigger the running of the script everyday. The script should check for the date and send neccesary mails. If your PHP is a CGI module than u can run it directly through crontab, else trigger it by running lynx on it.
0
 
LVL 8

Accepted Solution

by:
us111 earned 20 total points
Comment Utility
install php as cgi-bin (default compilation)

1. create a phpscript
#!/pathtophp/bin/php
<?
 here is the script, check date, send mail....
?>

2. save the file as yourfile.php

3. chmod 700 yourfile.php

4. create a crontab file that you run everyday: crontab.txt
0 0 * * * /pathto_yourfile.php

5. crontab crontab.txt
0
 
LVL 4

Expert Comment

by:kalosi
Comment Utility
Hello,

you even don't need to install php as cgi-bin. We are using
an alternative solution:

download the libwww perlmodule. After building it it creates
the following binaries:

GET and POST. these binaries represent the basic HTTP protocol commands.

create a date checker in the script which you are useing as described abow and then simply put a line like this to your crontab file

0 0 * * * GET -t 1000 http://path_to_script/script_name.php >
 /redirect_the_output/for_some_logging

the -t switch is the timeout of the GET request

bye

0
 
LVL 8

Expert Comment

by:us111
Comment Utility
didn't know this solution.
But the problem is that if you need to have your script secured you cannot because you call an URL. So you php script must be into the web root. With php (as cgi-bin) you can have it where you wish
0
 

Expert Comment

by:timothyha
Comment Utility
I think you might try another option if you don't have access to CRON. You can put that mailing script code in the index.php of your site. Every visitor then will trigger the check whether email has been sent or not. I don't think if you add too much time to that ONE good visitor who will work for you. But in case on June 24 nobody comes to your site, email will not be sent out :-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now