简体   繁体   English

Cron作业不发送邮件

[英]Cron job doesn't send mail

My cron job is run but no email is sent. 我的Cron作业已运行,但未发送电子邮件。

/usr/bin/php -f /home/user/public_html/test/cron/checklist.php task=client

result = OK 结果=确定

<?php
//get parameter from URL 
$argv = $_SERVER['argv'];
$task = explode("=", $argv[1]);
?>

result = OK 结果=确定

Complication start here ! 并发症从这里开始!

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo.'<br>';
} else {
    echo "Message sent!<br>";
} 

It says "Message sent!" 它说“消息已发送!” but no email is sent! 但没有发送电子邮件! When I run it from a web page as a test, it works and sends mail 当我从网页上运行它作为测试时,它可以工作并发送邮件

I use phpmailer to send. 我用phpmailer发送。

Try /usr/bin/php -f /home/user/public_html/test/cron/checklist.php client 尝试/usr/bin/php -f /home/user/public_html/test/cron/checklist.php client

Also, in your PHP code, differentiate between web server handling and command-line handling. 另外,在您的PHP代码中,区分Web服务器处理和命令行处理。 Here's an example: 这是一个例子:

if (php_sapi_name() == 'cli') {
    echo "this is command line";
    $task = $argv[1];
} else {
    echo "run from a web server";
    $argv = $_SERVER['argv']; 
    $task = explode("=", $argv[1]);
}
echo "\n task =";
echo $task;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM