Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
sending data with attachment doesn't work Cronjob

I dont know alot about cron job but i have a php file which sending data with attachment when i run it using the browser it's working fine and attachment is sent ,but if i use cron job to run it ,it never goes with the attachment. here is the cron job command-line :

/opt/php54/bin/php /home/username/public_html/path/to/myscript.php

and here is the place of error in the php file ,as the cron job sending me email with "Some how file :hhshd.jpg is not exist!" , however the data with attachment is sent successfully when i use the browser.

 if (!file_exists("uploads/" .  $fileName))
            {
                die("Some how file :$fileName is not exist!");
            } 

Note: i am using the cronjob of Hostgator.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Problem solved i have used this cron job command:

curl http://yoursite/path/to/publish.php
over 4 years ago · Santiago Trujillo Report

0

One possible reason cold be when you run the script through browser, the Apache user is able to create the attachment file and send it.

But when cronjob is not able to create attachment file due to permission issue.

You can try using 'sudo' in your cronjob or try changing the permission of the directory where you are creating the attachment.

over 4 years ago · Santiago Trujillo Report

0

It is most likely to be an ownership & permissions problem. What you have to put in your cron config depends on where you've put it and what user your web server runs as. If you want it to run at 5am each day, it's in /etc/crontab and www-data is your web server user, you would need an entry like this:

0 5    * * *   www-data    /opt/php54/bin/php /home/username/public_html/path/to/myscript.php

If it's in the web server user's own crontab file, it would skip the user name field. You would edit it using crontab -u www-data -e, and add a line like this:

0 5 * * * /opt/php54/bin/php /home/username/public_html/path/to/myscript.php

One other issue may be that the current working directory may be different, so you may need to set the command to include a cd to the directory your script is in first, like this:

cd /home/username/public_html/path/to && /opt/php54/bin/php myscript.php

If you want to receive any error output from a cron job, set a MAILTO environment variable by adding a line like this to the cron file before you run the command:

MAILTO=user@example.com
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!