Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
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 Respuestas
Responde la pregunta

0

Problem solved i have used this cron job command:

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

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda