简体   繁体   中英

PHP Error: Fatal error: Call to undefined method

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!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM