PHP Error: Fatal error: Call to undefined method

不打扰是莪最后的温柔 提交于 2019-12-11 19:07:59

问题


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

My mail class:

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);
}
}

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();

Line where the error is happening:

$mail->sendTo(User::getMailFromUsername($username));

I'd appreciate any help, thanks!

EDIT: Made some change to names of method and var to, so you can understand it better. BUT STILL GIVING SAME ERROR!!


回答1:


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.



来源:https://stackoverflow.com/questions/20023112/php-error-fatal-error-call-to-undefined-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!