2016-11-09 60 views
0

我試圖做一個鉤子,我得到了一個foreach函數的問題。WHMCS鉤子 - foreach錯誤

我得到了以下錯誤,但我使用的是從http://docs.whmcs.com/Email_Templates的smarty foreach函數。

// Call WHMCS API - send admin email 
$command = "sendadminemail"; 
$adminuser = "admin"; 
$values["customsubject"] = "Daily Cron Report"; 
$values["custommessage"] = "Domains Report<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "{$active_domains_count} Active Domains<br>{$expired_domains_count} Expired Domains<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "Expired Domains"; 
$values["custommessage"] .= "{foreach from=$expired_domains item=expireddomains}-{$expireddomains.domain}<br>{/foreach}"; 
$values["customvars"] = array("active_domains_count" => $active_domains_count, "expired_domains_count" => $expired_domains_count, "expired_domains" => $expired_domains); 
$values["type"] = "system"; 

$results = localAPI($command, $values, $adminuser); 

Parse error: syntax error, unexpected '.', expecting '}' in /includes/hooks/dailycron.php on line 24

有什麼建議?提前謝謝

回答

1

使用php -l來調試sintax錯誤,你的問題在第11行,用單引號關閉字符串而不是雙引號來修復它。

<?php 
// Call WHMCS API - send admin email 
$command = "sendadminemail"; 
$adminuser = "admin"; 
$values["customsubject"] = "Daily Cron Report"; 
$values["custommessage"] = "Domains Report<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "{$active_domains_count} Active Domains<br>{$expired_domains_count} Expired Domains<br>"; 
$values["custommessage"] .= "--------------------<br>"; 
$values["custommessage"] .= "Expired Domains"; 
$values["custommessage"] .= '{foreach from=$expired_domains item=expireddomains}-{$expireddomains.domain}<br>{/foreach}'; 
$values["customvars"] = array("active_domains_count" => $active_domains_count, "expired_domains_count" => $expired_domains_count, "expired_domains" => $expired_domains); 
$values["type"] = "system"; 

$results = localAPI($command, $values, $adminuser); 
+0

我使用電子郵件HTML以外的foreach修復了這個問題。它的工作。 Smarty foreach不起作用 –