1

I have written a php file which sends email which is running via browser correctly. .I want to automatically send mails to user so i set up a job using "cron" after every 15 minutes

My php file name is "mail.php" and it is under folder "/public_html/myfolder/mail.php"

I have writen the command as

php -f /public_html/myfolder/mail.php

but it is showing error as "No input file specified."

so i tried using

/usr/local/bin/php -f /public_html/myfolder/mail.php

but the error was

"Could not open input file: /public_html/suvichar/mail.php

i have given the 777 permission to "mail.php"

can you please tell me what might be the issue can anybody give me exact command for cron to execute php file

4
  • Can the owner run the cron? r/w permission are not enough, if not set to the right owner. Commented Oct 8, 2011 at 19:36
  • I have a CPanel through which i can add cron jobs i just need to specify the command to execute..and i have given 777 permision Commented Oct 8, 2011 at 19:37
  • I have given 777 (r/w/x) permission for all U/o/G to "mail.php" Commented Oct 8, 2011 at 19:42
  • 3
    Is public_html really in the root of your file system? I would assume not. If I'm correct, use the full path to the file, or the relative path from the directory you're actually in. Commented Oct 8, 2011 at 19:55

2 Answers 2

1

Normally public_html is located in the /var/www (or similar directory). For FreeBSD the location of public_html is /usr/home/<username>/public_html. You already stated you put execute permissions. For any one else looking to add execute permission on a file you run this at the command prompt:

 chmod +x scriptname.php

Second you need to make sure you include the path to php at the top of your php file

 #!/usr/bin/php

--- OR --- (FreeBSD) and for you according to your question

 #!/usr/local/bin/php

When you call the cron job in your crontab file you use

 crontab -e

Add this line to the file and save: 15 * * * * /absolute/path/to/mail.php

# (This states that the script will run every 15 minutes everyday.)
# ------------- minute (0 - 59)
# | ----------- hour (0 - 23)
# | | --------- day of month (1 - 31)
# | | | ------- month (1 - 12)
# | | | | ----- day of week (0 - 6) (Sunday=0)
# | | | | |     * - Any day/month/hour
 15 * * * *     /absolute/path/to/mail.php
Sign up to request clarification or add additional context in comments.

1 Comment

I would also check your php script to make sure you do not need to pass a file with it.
0

hey guys it finally worked for me You guys were right public_html wasnt root directory of my server. Actullay via FTP i was able to see only structure below

/public_html.......

the Absolute path was

/home/primary_ftp_username/public_html/myfolder/file_name.php

thank you :D

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.