dongzhang7382 2013-08-05 11:24
浏览 38
已采纳

访问URL发送的邮件,但使用批处理文件运行时,SMTP Connect()失败

I have a problem with batch file

if I access: http://localhost:8080/cron/cron.php I got email sent with message Yeah, message send via Gmail

this my cron.php

<?php   
require_once 'simplehtmldom\simple_html_dom.php';
require_once 'sites.php';
require_once 'send_mail.php';
ini_set('display_errors','on');
foreach ($site_list as $name => $link){
    $command = "C:\\Python27\\python C:\\webcheck\\webcheck.py -o C:\\wamp\\www\\cron\eports\\$name $link";   
    $output =   shell_exec($command);   
    $log_file = "C:\\wamp\\www\\cron\\log.txt";
    $fh = fopen($log_file,'w') or die('can not open file');
    fwrite($fh, $output);
    fclose($fh);
}


/*Scan folder for reporting */
$path = 'C:\\wamp\\www\cron\eports\\';
$msg = '';
foreach (new DirectoryIterator($path) as $fileInfo) {
    if($fileInfo->isDir() && !$fileInfo->isDot()) {
        // Do whatever
        $webcheck = $fileInfo->getFilename() ;
        $html = file_get_html($path.$webcheck.'\\badlinks.html');
        $es = $html->find('div[class="content"]', 0);
        $msg .="<h2>BADLINKS $webcheck</h2>";             
        $msg .= $es->innertext; // Some Content 
    }
}

$subj = $_subj; 
$to = $_to;
$from = $_from;
$name = $_name;

if (smtpmailer($to, $from, $name, $subj, $msg)) {
    echo 'Yeah, message send via Gmail';
} else {
    if (!smtpmailer($to, $from, $name, $subj, $msg, false)) {
        if (!empty($error)) echo $error;
    } else {
        echo 'Yep, the message is send (after doing some hard work)';
    }
}

?>

But with this cron.bat

C:\wamp\bin\php\php5.3.5\php C:\wamp\www\cron\cron.php

I go to cmdand type cron.bat

I got messsage Mail error: SMTP Connect() failed.

Do you have any idea?

Thanks

  • 写回答

1条回答 默认 最新

  • douang1243 2013-08-05 11:46
    关注

    Remember that cron jobs will be using the PHP CLI. And the PHP CLI uses a different php.ini file to Apache.

    Make sure you have all the required extension activated within this other php.ini file.

    I would imagine the php_smtp extension is not activated.

    Ahh I see you are using WAMP so the PHP CLI version of the php.ini file will be in c:\wamp\bin\php\php5.x.y\php.ini.

    Where as the Apache version is in c:\wamp\bin\apache\apache2.x.y\bin\php.ini if you need to compare which extension you have activated in Apache PHP to those not activated in the PHP CLI

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置