0
votes

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:[email protected]';
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
So where is $mail being set as an instance of your Mail class? - Mark Baker
where did you initialized the class? - Jason OOO
Search for $mail = new Mail; on your code , if not found. Just add it. - Shankar Damodaran
Are you sure that's the line? Mail::to() (static) and Mail->to() (instance) are different types of functions. - doublesharp
You have a public variable $mail->to with the same name as a public method $mail->to(). I'd guess that's causing the problem. Try changing the name on one of them. - user1864610

1 Answers

6
votes

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.