0

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

11
  • 1
    So where is $mail being set as an instance of your Mail class? Commented Nov 16, 2013 at 19:59
  • where did you initialized the class? Commented Nov 16, 2013 at 19:59
  • Search for $mail = new Mail; on your code , if not found. Just add it. Commented Nov 16, 2013 at 20:01
  • 2
    Are you sure that's the line? Mail::to() (static) and Mail->to() (instance) are different types of functions. Commented Nov 16, 2013 at 20:01
  • 1
    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. Commented Nov 16, 2013 at 20:02

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.