0

我有 2 页:

自动化.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
4

1 回答 1

0

The problem is sendemail() is still not defined when you run include.

This is because the if(!function_exists("sendemail")) block will only execute AFTER the include, and thus, the function will not exist.

于 2013-09-23T08:27:50.243 回答