PHP错误:致命错误:调用未定义的方法 [英] PHP Error: Fatal error: Call to undefined method
本文介绍了PHP错误:致命错误:调用未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Mail类出现问题.它以前工作过,但现在我不知道发生了什么.这是错误:
I'm having a problem with my Mail class. It was working before, but now i'm not sure what happened. here is the error:
Fatal error: Call to undefined method Mail::sendTo() in C:\...\web\modules\register.php on line 30
我的邮件类别:
class Mail
{
public static $Headers = 'From:akshay@myemail.com';
public $sendtowho;
public $subject;
public $message;
public $template;
public function sendTo($who='')
{
$this->sendtowho = $who;
}
public function with($subj='',$template)
{
$this->subject = $subj;
$this->template = $template;
}
public function addVars($variables)
{
$TemplateHandler = new Template('mail');
$this->message = $TemplateHandler->renderContent($this->template, $variables);
}
public function send()
{
mail($this->sendtowho, $this->subject, $this->message, self::$Headers);
}
}
我的register.php
My register.php
$mail = new Mail();
$mail->sendTo(User::getMailFromUsername($username));
$mail->with(' Registration Info','registration');
$mail->addVars(array('name' => User::getNameFromUsername($username), 'regKey' => $regKey));
$mail->send();
发生错误的行:
$mail->sendTo(User::getMailFromUsername($username));
感谢您的帮助,谢谢!
对方法和var to的名称进行了一些更改,因此您可以更好地理解它.但是仍然会出现相同的错误!
Made some change to names of method and var to, so you can understand it better. BUT STILL GIVING SAME ERROR!!
推荐答案
我已解决此问题.只需将我的班级名称从Mail更改为MailInterface.邮件类别已经被其他东西占用了.我在PHP 5.5上使用XAMPP.
I fixed the problem. Just need to change the name of my class from Mail to MailInterface. Mail class is already taken by something else. I am using XAMPP with PHP 5.5.
这篇关于PHP错误:致命错误:调用未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文