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/monitor.pl)
Jul 21 03:15:01 veepiz crond[3820]: (root) CMD (/etc/webmin/virtual-server/collectinfo.pl)
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 = '.veepiz.com';
    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 = "support@veepiz.com";
                $x->FromName = "Veepiz";
                $x->AddReplyTo("support@veepiz.com", "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";
  • 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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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