phpList with crontab: USER environment variable is not defined

When trying to automate processing of the mail queue and/or bounces in phpList, I came across the following error when calling the phplist command line script from a crontab:
Error: USER environment variable is not defined, cannot do access check. Please make sure USER is defined.
This happens because when a crontab executes, the $USER variable is not set. We must set it in our script. So open up the phplist file and add the following:
USER=youusername
export USER

The entire file should now look like this:
CONFIG=/path/to/phplist/config/config.php
export CONFIGUSER=yourusername
export USER/path/to/php /home/yourusername/path/to/phplist/admin/index.php $*

Note that you also must set the $commandline_users variable in your config/config.php:
$commandline_users = array("yourusername");
With all of that in place, you can automate your queue and bounce processing with a crontab like this (adjust your paths accordingly):
# Suppress crontab emails
MAILTO=""
# Process phplist queue daily, every half hour
0,30 * * * * /home/yourusername/phplist -pprocessqueue
# Process phplist bounces once a day, 5am
0 5 * * * /home/yourusername/phplist -pprocessbounces

One response to “phpList with crontab: USER environment variable is not defined”

  1. shtikl says:

    Hi, thanks for the description. Sounds great… but: could this work somehow if my hoster only allows me to call URLs as CronJobs?