Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Klasa wysyłająca maila, Dodanie nagłówków
Lejto
post 2.07.2009, 11:49:52
Post #1





Grupa: Zarejestrowani
Postów: 1 385
Pomógł: 48
Dołączył: 23.05.2007

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


Mam klase wysyłającą maila
  1. <?
  2. class Emailer
  3. {
  4.    private $sender;
  5.    private $recipients;
  6.    private $subject;
  7.    private $body;
  8.    
  9.    function __construct($sender)
  10.    {
  11.        $this->sender = $sender;
  12.        $this->recipients = array();
  13.    }
  14.    public function addRecipients($recipient)
  15.    {
  16.        array_push($this->recipients, $recipient);
  17.    }
  18.    public function setSubject($subject)
  19.    {
  20.        $this->subject = $subject;
  21.    }
  22.    public function setBody($body)
  23.    {
  24.        $this->body = $body;
  25.    }
  26.    public function nag($email)
  27.    {
  28.               $header = "From:  <$email>\n";
  29.              $header .= "MIME-Version: 1.0\n";
  30.              $header .= "Content-type: text/html; charset=utf-8\n";
  31.              $header .= "Return-Path: <$email>";
  32.    }
  33.    public function sendEmail()
  34.    {
  35.        
  36.        foreach ($this->recipients as $recipient)
  37.        {
  38.            $result = mail($recipient,$this->subject,$this->body,$this->nag);
  39.            if($result)
  40.            {
  41.            echo '<div id="good">';
  42.            echo 'Wiadomość została wysłana';
  43.            echo '</div>';
  44.             }
  45.        }
  46.    }
  47.    
  48. }
  49. ?>

Dodałem funkcje z nagłówkami nag();
Uruchamiam tak:
  1. <?php
  2. $email = new Emailer($email); //adres od
  3.            $email->addRecipients("agencik@gmail.com"); // adres do
  4.            $email->setSubject($temat);
  5.            $email->setBody($wiadomosc);
  6.            $email->nag($email);
  7.            $email->sendEmail();
  8. ?>

wszystko działało dobrze tylko jak dodałem te nagłówki to otrzymuje taki błąd
Kod
Catchable fatal error: Object of class Emailer could not be converted to string in /home/s/public_html/s-s.eu/mail.class.php on line 28

w lini 28 znajduje się
  1. <?php
  2. $header = "From:  <$email>\n";
  3. ?>


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 11:19