Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

0

Problem solved i have used this cron job command:

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda