Witam!
Raczkuje w OOP. Natknąlem się na taki błąd:
Cytat
Warning: Invalid argument supplied for foreach() in /homez.108/micneo/www/test/class.emailer.php on line 43
class.emailer.php
<?
// class.emailer.php
class Emailer
{
private $sender;
private $recipients;
private $subject;
private $body;
function __construct($sender)
{
$this->sender = $sender;
$this->recipients = array(); }
public function addRecipients($recipient)
{
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function setBody($body)
{
$this->body = $body;
}
public function sendEmail()
{
foreach ($this->recipients as $recipient)
{
$result = mail($recipient, $this->subject, $this->body, "From: {$this->sender}r\n");
if ($result) echo "Wiadomość została wysła do {$recipient}<br/>";
}
}
}
class HtmlEmailer extends Emailer
{
public function sendHTMLEmail()
{
foreach ($this->recipients as $recipient)
{
$headers = 'MIME-Version: 1.0' . "r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-2' .
"r\n";
$headers .= 'From: {$this->sender}' . "r\n";
$result = mail($recipient, $this->subject, $this->body, $headers);
if ($result) echo "Wiadomość w formacie HTML została wysłana do {$recipient}<br/>";
}
}
}
?>
oraz plik emailer.php
<?php
include_once("class.emailer.php");
$mailHTML = new HtmlEmailer("adres@mail.pl");
$mailHTML->addRecipients("odbioraca@mail.pl");
$mailHTML->setSubject("temat");
$mailHTML->setBody("test");
$mailHTML->sendHTMLEmail();
?>
Nie wiem co jest nie tak. Jak się wczesniej bawiłem dziedziczeniem to śmigało (nie wykorzystalem pętli foreach). Nie wiem co źle robie. Prosze o pomoc.
Pozdrawiam!