2013-09-23 438 views
0

我有2頁:PHP函數致命錯誤:

automate.php

automate.php checkemail.php是:

<?php include 'scripts/checkemail.php'; ?> 

和:

<?php 
if(!function_exists("sendemail")) 
{ 
    function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto,$cc='') 
    { 
     if(filter_var($email_to, FILTER_VALIDATE_EMAIL)) 
     { 
      require_once "/usr/local/lib/php/Mail.php"; 

      $from = $email_from; 
      $to = $email_to; 
      $subject = $email_subject; 
      $body = $email_body; 

      $host = "mail.domain.co.uk"; 
      $username = "[email protected]"; 
      $password = "*********"; 

      $headers = array ('From' => $from, 
       'To' => $to, 
       'Cc' => $cc, 
       'Subject' => $subject, 
       'Content-type' => 'text/html'); 
      $smtp = Mail::factory('smtp', 
       array ('host' => $host, 
      'auth' => true, 
      'username' => $username, 
      'password' => $password)); 

      $rec = $to.', '.$cc; 

      $mail = $smtp->send($rec, $headers, $body); 
     } 
    } 
} 
?> 

th連接上checkemail.php我打電話這個功能:

sendemail("[email protected]","Support <[email protected]>","Contact Not Found",$contact_not_found_email,"[email protected]"); 

,但我得到這個錯誤:

Fatal error: Call to undefined function sendemail() in /home/integra/public_html/automate/scripts/checkemail.php on line 180 
+0

嘗試使用'require'而不是'include'來確保文件被找到。 – urzeit

+0

我已經嘗試了require_once,並要求和include_once,但仍然是相同的錯誤 – charlie

+1

您在automate.php中包含checkemail.php。你可以在automate.php中定義一個sendmail函數,然後嘗試在checkemail.php中調用它。這應該如何工作?你應該在checkmail.php中包含automate.php,而不是相反。 – Kethryweryn

回答

0

問題是sendemail()當您運行include尚未定義。

這是因爲if(!function_exists("sendemail"))塊只會在include之後執行,因此函數將不存在。