Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have setup dkim on my server using opendkim(centos). when php executes mail command(on website eg forgot.php). it sends an email signed with DKIM. but i also setup a cron job to run mailcron.php which sends out emails.

i setup cron by typing crontab -e [ENTER] */5 * * * * php -q /var/www/html/mailcron.php [save]

OUTPUT from cron log

Jul 21 03:15:01 veepiz crond[3819]: (root) CMD (/etc/webmin/status/
Jul 21 03:15:01 veepiz crond[3820]: (root) CMD (/etc/webmin/virtual-server/
Jul 21 03:15:01 veepiz crond[3821]: (root) CMD (php -q /var/www/html/mailcron.php)

why are emails sent using cron not signing while those running directly from the site signing.

    $localpath = '';
    $domainpath = '';
    if (!$dblink)
        die('Could not connect to database.<br/>'.mysql_error());
    if (!(mysql_select_db($dbname,$dblink)))
        die('Could not select database<br/>'.mysql_error());

    $q="SELECT * FROM emailcron ORDER BY id ASC";
    if ($r)
        if (mysql_num_rows($r)>0)
            while ($o=mysql_fetch_object($r))
                $x = new PHPMailer();
                $x->From = "";
                $x->FromName = "Veepiz";
                $x->AddReplyTo("", "Veepiz");
                $x->WordWrap = 50;                                 // set word wrap to 50 characters
                $x->IsHTML(true);                                  // set email format to HTML
                $x->Subject = $o->subject;
                $x->Body    = nl2br($o->content);
                $x->AltBody = strip_tags($o->content);
                {   $c++;
                    $message .= "Message could not be sent. <br/>\n"; 
                    $message .= "Mailer Error: " . $x->ErrorInfo."<br/>\n"; 
                } else { $n++; mysql_query("DELETE FROM emailcron WHERE id=".$o->id); }                
            if (strlen($message)>0) 
                echo $message;      
            } else
                echo  "Mails sent:$n; Mails Failed:$c";
share|improve this question
Because something's different between how PHP sends mails as opposed to how cron sends mails. Your mail config and PHP scripts will be required to diagnose this. – womble Jul 21 '11 at 3:45
i dnt understand why this question has been down voted. its very valid – Sir Lojik Jul 21 '11 at 3:53

The cron job's shell environment is often different from a login shell. This should be the reason.

Also make sure you give the full path to PHP like

*/5 * * * * * /usr/local/php5/bin/php -q /var/www/html/mailcron.php

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.