Solved

Sending mail automatically.

Posted on 2001-06-05
5
226 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
ID: 6158206
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
ID: 6158741
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
ID: 6162738
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
ID: 6162756
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
ID: 6163501
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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