Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:58:12+00:00 2026-06-17T21:58:12+00:00

I have a cron cron job setup to send emails. It is executed using

  • 0

I have a cron cron job setup to send emails. It is executed using the following command:

/usr/bin/php -q /var/www/vhosts/domain.com/cron/job.php

When I execute the php script from a browser, the script sends emails as expected. It fails when run by the cron job.

I don’t see any errors in the maillog. Only difference is in the “from” line. When the script is executed from a browser, the log reads:

Jan 25 12:24:39 VMW01 qmail-remote-handlers[1001]: from=sender@domain.com

But when the cron job executes the script the “from” line becomes:

Jan 25 12:15:01 VMW01 qmail-queue-handlers[1000]: from=anonymous@VMW01.server.net

Oddly, the cron job will send emails when I remove the fifth parameter of the mail() line.

mail($email, $subject, $body, $headers, '-fsender@domain.com');

I would simply live with this, but if I remove the parameter, emails are often rejected by servers – which I presume is because the parameter is not set.

Any idea why this is happening and how I can fix it? I’d be happy to add more detail to this question in order to get to a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:58:13+00:00Added an answer on June 17, 2026 at 9:58 pm

    As @Michael said, most likely your cron job is using a different php.ini file. You can use the php_ini_loaded_file() function to see what file is loaded in your script – then run it from the command line, or your cron to see the difference with the web execution.

    My guess is that the problem arises because the php.ini for the cron job (same as command line) has safe_mode set, and when that is the case, you shouldn’t use the last parameter to the mail() function as it can fail. As evidence, if you look at the PHPMailer class there is a mail_passthru() method that simply calls the PHP mail() function under the covers. Notice that it leaves out the extra parameter when not in safe_mode:

    private function mail_passthru($to, $subject, $body, $header, $params) {
        if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) {
            $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
        } else {
            $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
        }
        return $rt;
    }
    

    You can load a specific php.ini file when calling php from the command line (or your cron job) like this:

    /usr/bin/php -q /var/www/vhosts/domain.com/cron/job.php -c /path/to/php.ini
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to setup a cron job command to execute an URL? /usr/bin/wget -q http://www.domain.com/cron_jobs/job1.php
I have a cron job the executes a PHP script. The cron is setup
EDIT: Cron line: /usr/bin/php /usr/local/yy/yy/yy/webspace/httpdocs/test.mysite.ie/test.php > /dev/null 2>&1 I have written a script that
I am trying to setup a CRON job using PHP, but am not having
I have a CRON job php script that I just set up not too
I have a PHP page that I run every minute through a CRON job.
I have a PHP script that has been running as a cron job. The
I have a cron job setup to look every 24 hours for a change
I've setup a Cron job in Google App Engine (Java) and have deployed it
Is it possible to setup a cron job from within a PHP script on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.