2013-08-05 53 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

沒有激活它擴展