Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending mail automatically.

Posted on 2001-06-05
5
Medium Priority
?
234 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
[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
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 80 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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