Results 1 to 5 of 5

Thread: Cron and php

  1. #1
    Join Date
    Feb 2004
    Posts
    9

    Unanswered: Sending mail automatically using pycron and php

    I have already install the Cron and I have the following php file: mail.php

    <?php

    $message="hihi";
    mail("barry_1030@yahoo.com.hk", "My Subject", $message);
    ?>

    how can I set the Cron and change the php file to send out the mail at specific time?
    Last edited by barry_1030; 02-24-04 at 07:28.

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Re: Cron and php

    Hi
    There are a few ways, each of which use the crontab command.
    Depending on the configuration of PHP in your Apache server (cgi or module).


    CGI
    Add the following line to the top of your script: #!/usr/local/bin/php -q

    The -q is for quiet mode.

    And by adding the scripts path to the crontab file located in /etc/ by typing crontab -e.
    This will open a file in vi, or your preferred editor, in the case of vi press the i key to enter insert mode.
    Add the following line

    1 0 * * * php /home/dir/tasks/email.php

    The to finish, press the escape key followed by semicolon ( x and !. These will save the modified file
    and you'll see a message saying "crontab: installing new crontab".

    Basically this line will run a the .php script 1 minute past midnight (0= 00:00 hours)


    MODULE
    By using a text based browser such as Lynx there is not need for the bash line above,
    only the adding of a line to the crontab file. By typing crontab -e a file will be opened in vi.
    As mentioned in the above instructions to navigate around vi, add the following line.

    1 0 * * * lynx -dump http://www.mydomain.com/email.php



    Another method exists in the form of PHPCLI (PHP Command Line Interface). Which was included
    in from version 4.2.0, but the attribute --enable-cli had to be explicitly typed. Since 4.3.0, however,
    the phpcli file is created by default, although the paths may have changed. I mention this as the CGI maybe
    replaced, renamed ....

    This is similar the the CGI method, but with 1 0 * * * php /home... becomming 1 0 * * * phpcli /home.


    In either method ensure that the permissions on the script are correct for the cron daemon to execute.
    trying chmod 755 email.php or chmod +x email.php should resolve this.

    More information regarding :

    The commandline can be found here:
    http://www.php.net/manual/en/features.commandline.php

    The CRONTAB settings can be found here:
    http://www.learninglinux.com/article57.html

    Regards

    Rajesh


    Originally posted by barry_1030
    I have already install the Cron and I have the following php file: mail.php

    <?php

    $message="hihi";
    mail("barry_1030@yahoo.com.hk", "My Subject", $message);
    ?>

    how can I set the Cron and change the php file to send out the mail at specific time?

  3. #3
    Join Date
    Feb 2004
    Posts
    9
    My system is Module.
    I try to use lynx to perform the job. However, it doesn't work.
    Please help.

    My tools:
    pycron http://www.kalab.com/freeware/pycron/pycron.htm
    windows XP
    apache
    php 4.34

  4. #4
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    cron and php

    lynx is a text based browser in linux. You can user internet explorer for this purpose here in windows. I the task property you can specify the file to be executed. ie mail.php, and the absolute path of the file. ie the server on which it is running. There sent the time where you want to run this task * in the time field indicated always.
    hope that it would be clear to you.
    Regards

    Rajesh


    Originally posted by barry_1030
    My system is Module.
    I try to use lynx to perform the job. However, it doesn't work.
    Please help.

    My tools:
    pycron http://www.kalab.com/freeware/pycron/pycron.htm
    windows XP
    apache
    php 4.34

  5. #5
    Join Date
    Feb 2004
    Posts
    9
    After a lot of experiment, I can perform what I want now.
    Here is the procedure to send mail automatically in specific time.

    Tools:
    Apache web server
    PHP
    Windows XP
    Pycron --------> http://www.kalab.com/freeware/pycron/pycron.htm

    1. First create a php file with mail() function. (remember to setup the required parameter (SMTP, sentmail_from) in php.ini )

    let's call it " mail.php " and put it in the folder of our server.

    e.g.
    <?php
    $to="xyz@yahoo.com";
    $subject="hi";
    $message="hi";
    mail($to, $subject, $message);
    ?>

    2. download the Pycron and install it

    3. edit the crontab.txt using the "crontab.txt Editor" or notpad
    e.g.
    * * * * * "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://192.192.20.14/mail.php

    4. then the mail will be sent automatically in every mins.
    Please replace the "*" to change to the specific time that you want.

    P.S. In the mail.php, you can make your own function to replace the value of from, subject and message in order to perform what you want.

    Hope this method can help all of you! ^o^
    Last edited by barry_1030; 02-24-04 at 08:48.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •