PHP函数致命错误:

时间:2013-09-23 08:17:21

标签: php

我有2页:

automate.php checkemail.php

automate.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 = "sending@domain.co.uk";
            $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);
        }
    }
}
?>

然后在 checkemail.php 我正在调用此函数:

sendemail("techsupport@domain.co.uk","Support <no-reply@domain.co.uk>","Contact Not Found",$contact_not_found_email,"no-reply@domain.co.uk");

但是我收到了这个错误:

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

1 个答案:

答案 0 :(得分:0)

运行sendemail()时,问题仍未定义include

这是因为if(!function_exists("sendemail"))块仅在包含后执行,因此该功能将不存在。