Solved

Sending mail automatically.

Posted on 2001-06-05
5
220 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now