Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dziedziczenie i pętla foreach
MicNeo
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 7
Dołączył: 21.11.2004
Skąd: Kraków / Nowy Sącz

Ostrzeżenie: (0%)
-----


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
  1. <?
  2. // class.emailer.php
  3. class Emailer
  4. {
  5.   private $sender;
  6.   private $recipients;
  7.   private $subject;
  8.   private $body;
  9.   function __construct($sender)
  10.   {
  11.      $this->sender = $sender;
  12.      $this->recipients = array();
  13.   }
  14.  
  15.   public function addRecipients($recipient)
  16.   {
  17.      array_push($this->recipients, $recipient);
  18.   }
  19.   public function setSubject($subject)
  20.   {
  21.      $this->subject = $subject;
  22.   }
  23.   public function setBody($body)
  24.   {
  25.      $this->body = $body;
  26.   }
  27.   public function sendEmail()
  28.   {
  29.      foreach ($this->recipients as $recipient)
  30.      {
  31.         $result = mail($recipient, $this->subject, $this->body,
  32.            "From: {$this->sender}r\n");
  33.         if ($result) echo "Wiadomość została wysła do
  34.            {$recipient}<br/>";
  35.      }
  36.   }
  37. }
  38.  
  39. class HtmlEmailer extends Emailer
  40. {
  41.   public function sendHTMLEmail()
  42.   {
  43.         foreach ($this->recipients as $recipient)
  44.         {
  45.            $headers  = 'MIME-Version: 1.0' . "r\n";
  46.            $headers .= 'Content-type: text/html; charset=iso-8859-2' .
  47.               "r\n";
  48.            $headers .= 'From: {$this->sender}' . "r\n";
  49.            $result = mail($recipient, $this->subject, $this->body,
  50.               $headers);
  51.            if ($result) echo "Wiadomość w formacie HTML została wysłana do
  52.               {$recipient}<br/>";
  53.      }
  54.   }
  55. }
  56. ?>


oraz plik emailer.php
  1. <?php
  2. include_once("class.emailer.php");
  3.  
  4. $mailHTML = new HtmlEmailer("adres@mail.pl");
  5. $mailHTML->addRecipients("odbioraca@mail.pl");
  6. $mailHTML->setSubject("temat");
  7. $mailHTML->setBody("test");
  8. $mailHTML->sendHTMLEmail();
  9.  
  10. ?>


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!
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 07:03