PHPMailer函数不包括在内

时间:2014-02-12 21:11:54

标签: php error-handling

我有这个文件由我为PHPMailer(mail.php)制作:

<?php
function Send($to,$subject,$msg,$from){
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.com"; // SMTP server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user';                            // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->From     = "$from";
$mail->AddAddress("$to");
$mail->Subject  = "$subject";
$mail->Body     = "$msg";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
}
}
if(function_exists("Send")){
    echo "Function is defined";
}
else{
    echo "Function isn't defined";
}

?>

我将它包含在处理php文件(report.php)的联系表格中:

<html>
 <head>
    <title>Aliens Abducted Me - Report an Abduction</title>
 </head>
 <body>
    <h2>Aliens Abducted Me - Report an Abduction</h2>
    <?php
    $url="http://127.0.0.1/phpmailer/mail.php";
    echo "$url";
    include_once($url);
        $name=$_POST['firstname']." ".$_POST['lastname'];
        $how_many=$_POST['howmany'];
        $what_they_did=$_POST['whattheydid'];
        $other=$_POST['other'];
        $when_it_happened=$_POST['whenithappened'];
        $how_long=$_POST['howlong'];
        $alien_description=$_POST['aliendescription'];
        $fang_spotted=$_POST['fangspotted'];
        $email=$_POST['email'];

        $to="user@mail.com";
        $subject='Aliens Abducted Me - Abduction Report';
        $msg="$name was abducted $when_it_happened and was gone for $how_long.\n".
            "Number of Aliens : $how_many\n".
            "Alien description : $alien_description\n".
            "What they did : $what_they_did\n".
            "Fang spotted : $fang_spotted\n".
            "Other comments : $other";

        Send($to,$subject,$msgm,$mail);   //this is the problematic line

        echo 'Thanks for submitting the form.<br />';
        echo 'You were abducted '.$when_it_happened.'<br />';
        echo ' and were gone for '.$how_long.'<br />';
        echo "Number of aliens : ".$how_many.'<br />';
        echo "Describe them : ".$alien_description.'<br />';
        echo "The aliens did this : ".$what_they_did.'<br />';
        echo "Was Fang there?".$fang_spotted.'<br />';
        echo "Other comments : ".$other.'<br />';
        echo "Your email address is ".$email;

    ?>

这只是我正在学习PHP的一本书的例子,所以不要惊慌失措:)))...我的问题是,当我提交表单时,我总是得到这个错误:

Fatal error: Call to undefined function Send() in path/report.php on line 30

即使function_exists()的计算结果为true,也会发生错误......为什么?

编辑:

我正在使用localhost ant这些是我文件的路径:

mail.php : localweb\phpmailer\mail.php
report.php : localweb\hf_php\ch01\initial\aliens\report.php

谢谢!

1 个答案:

答案 0 :(得分:3)

您需要直接从本地文件系统中包含该文件。您目前拥有的是通过网络获取文件,包括从您的网络服务器发送的执行脚本的结果。

鉴于您的文件结构:

mail.php: localweb\phpmailer\mail.php
report.php: localweb\hf_php\ch01\initial\aliens\report.php

report.php中,您的include语句应为:

include_once("../../../../phpmailer/mail.php");