2013-08-05 54 views
0

我有一个批处理文件邮件失败时批处理文件运行

一个问题,如果我访问:http://localhost:8080/cron/cron.php 我得到了电子邮件,消息发送Yeah, message send via Gmail

这个我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\\reports\\$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\\reports\\'; 
$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)'; 
    } 
} 

?> 

但有了这个cron.bat

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

我去cmd,并键入cron.bat

我得到消息话题Mail error: SMTP Connect() failed.

你有什么想法?

感谢

回答

1

记住,cron作业将使用PHP CLI。而PHP CLI使用不同的php.ini文件到Apache。

确保您已在此其他php.ini file内激活了所有必需的扩展程序。

我会想象php_smtp扩展未被激活。

啊我看你使用的是WAMP,因此PHP CLI版本的php.ini文件将在c:\wamp\bin\php\php5.x.y\php.ini

凡于Apache的版本是在c:\wamp\bin\apache\apache2.x.y\bin\php.ini如果你需要比较你在Apache的PHP激活那些在PHP CLI

没有激活它扩展