I’m new to OOP and could use some help. My class is not working:
class Email {
private $to = 'shummel@...';
public $subject;
public $body;
public function send() {
$this->addHeader('From: moreinfo@ulsinc.com' . "\r\n" .
'Reply-To: moreinfo@ulsinc.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n");
$this->addHeader("MIME-Version: 1.0\r\n");
$this->addHeader("Content-Type: text/html; charset=ISO-8859-1\r\n");
$sent = mail($this->to, $this->subject, $this->body, $this->headers);
return $sent;
}
private function addHeader($header) {
$this->headers .= $header;
}
}
And here I am calling it:
$mail = new Email();
$mail = new Email;
$mail->subject($_POST['subject']);
$mail->body($_POST['body']);
$mail->send();
I’ve done print_r on the $_POST and the values are there. There are no problems with our mail server. So I’m not sure what I’m doing wrong. I’d appreciate some help. Thanks.
I recommend using PHPMailer, which is a free and mature mailer class for PHP.