Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Email not fetching on cron

We're using OS Ticket and during the day whilst we're using it it will happily fetch emails from the configured inbox.
However it won't fetch them on a cron so we don't get alerts sent to the techs when a new ticket is pulled from the tickets inbox.   I can't see howto get this to work

I set up a cronjob as follows
* * * * * /var/www/
to run my script every minute.

script is:

echo "getting mail 2" >> cronlog_$(date +\%Y-\%m-\%d_\%H-\%M).log
/usr/bin/php /var/www/html/help/api/cron.php >> cronlog_$(date +\%Y-\%m-\%d_\%H-\%M).log

and its set to executable
-rwxr-xr-x. 1 root   root   155 Sep 28 14:56 ../

this runs and creates datestamped files so I know its running.  The datestamped file only contains one line, no output from cron.php

I tried adding echos into the cron.php file to work out how far it was getting but i just kept getting errors about headers already sent.
I tried the wget method from here :
wget -q -O /dev/null --user-agent=<API key here> http://<host & path goes here>/api/cron.php
but when I ran it like this 
wget  --user-agent=<API key here> http://<host & path goes here>/api/cron.php
i got this message : 
cron.php only supports local cron calls - use http -> api/tasks/cron
and that failed saying file not found

So outgoing mails work, incoming mails work when triggered by the loading of OS ticket web pages but running the "get mail" scripts manually or in a cron doesn't work.  Any ideas where to start looking?


  • Server Information
    osTicket Version v1.10 (901e5ea)  Upgrade — v1.10.1 is available
    Web Server Software Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/5.6.31
    MySQL Version 10.1.26
    PHP Version 5.6.31
    PHP Extensions
    gdlib Used for image manipulation and PDF printing
    imap Used for email fetching
    xml XML API
    xml-dom Used for HTML email processing
    json Improves performance creating and processing JSON
    mbstring Highly recommended for non western european language content
    phar Highly recommended for plugins and language packs
    intl Highly recommended for non western european language content
    fileinfo Used to detect file types for uploads
    APCu Improves overall performance
    Zend Opcache Improves overall performance
    PHP Settings
    cgi.fix_pathinfo "1" is recommended if AJAX is not working
    date.timezone Europe/London
    Database Information and Usage
    Schema osticket (localhost)
    Space Used 90.95 MiB
    Space for Attachments 64.61 MiB
    Timezone BST (Interpreted as Europe/London)
  • Change the email configuration settings from "Fetch on autocron", to "Fetch on cron".
  • On "Incoming emails" section of  Admin panel | Emails tab | Settings 
    There are 2 tick boxes : Email fetching  : Enable is ticked , fetch on autocron is unticked.
    On the emails tab in the section Fetching Email via IMAP or POP  Status is enabled for the address I'm using.

    Autocron is no longer appearing in the System logs.

    I've sent an email,checked its in the inbox of the account we use,  and waited 5 minutes (cron it set to run every  minute which is confirmed by the script above creating a timestamped file.   The email wasn't collected.

    I've run  /usr/bin/php /var/www/html/help/api/cron.php as root from the shell and the email is still sitting in the inbox with no ticket generated.

    I'm confident that the email settings are correct at they work using autocron.

    Where else should I look?

  • Hmm
    found this code in my OST-config

    // If page requires SSL (forced true here), and we're not in SSL mode,
    // redirect to the SSL version of the page

    if($_SERVER['SERVER_PORT'] != 443) {
         header("HTTP/1.1 301 Moved Permanently");
         header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

                /* CUSTOM CODE END */

    which when removed  cures the issue.  But i was using this to force https pages for this ticket system. Looks like I need to find another way...
  • Here is the "other way".  IN the bottom on ost-config.php add these lines:

    // If page requires SSL (forced true here), and we're not in SSL mode,
    // redirect to the SSL version of the page
    // only add this if running via web page, eg not if called from cron
            if($_SERVER['SERVER_PORT'] != 443) {
                    header("HTTP/1.1 301 Moved Permanently");
                    header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);


    this now only forces https when its being served by apache, not when its called by cron on the local PC (in which case it would return "cli".  Not tested.  Use at your own risk. YMMV etc.

  • Many thanks cjohnsonuk for posting this. Spent about four hours trying to solve this issue and your solution was just the ticket (sorry, could'nt resist)!
  • Surely an apache config or .htaccess rule is better? 
  • Not if you're using IIS!

    It surprises me that in this day and age that it hasn't been implemented in the release code. Who wants to allow non-encrypted logins?
  • ...?

    @JasonTicket this does not appear to be your thread.  So I really have no idea what it is you think that your saying.  The thread opener is running Apache, so @Grizly comment about using an apache config or an .htaccess rule makes a lot more sense then editing the core files.  Sure it doesn't make sense in your user case... but then since you appear to be running IIS you would edit your web.config instead.
Sign In or Register to comment.