Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][html] Błąd przy przesyłaniu html
Wolfie
post
Post #1





Grupa: Zarejestrowani
Postów: 686
Pomógł: 0
Dołączył: 10.11.2008
Skąd: Łódź

Ostrzeżenie: (20%)
X----


Witam

Napisalem sobie taka prostą funkcje do przesyłania maili :

  1. <?php
  2.  
  3.    class SimpleMail {
  4.        public $to = NULL;
  5.        public $cc = NULL;
  6.        public $bcc = NULL;
  7.        public $from = NULL;
  8.        public $subject = '';
  9.        public $body = '';
  10.        public $htmlbody = '';
  11.        public $send_text = TRUE;
  12.        public $send_html = FALSE;
  13.        private $message = '';
  14.        private $headers = '';
  15.        
  16.        public function send ($to = NULL, $subject = NULL, $message = NULL, $headers = NULL) {
  17.            
  18.            if(func_num_args() >= 3) {
  19.                $this->to = $to;
  20.                $this->subject = $subject;
  21.                $this->message = $message;
  22.                if ($headers) {
  23.                    $this->headers = $headers;
  24.                }
  25.            } else {
  26.                if ($this->from) {
  27.                    $this->headers .= 'From: '.$this->from."r\n";
  28.                }
  29.                if ($this->cc) {
  30.                    $this->headers .= 'Cc: '.$this->cc."r\n";
  31.                }
  32.                if ($this->bcc) {
  33.                    $this->headers .= 'Bcc: '.$this->bcc."r\n";
  34.                }
  35.                
  36.                if ($this->send_text and !$this->send_html) {
  37.                    $this->message = $this->body;
  38.                } elseif ($this->send_html and !$this->send_text) {
  39.                    $this->message = $this->htmlbody;
  40.                    $this->headers .= "MIME-Version: 1.0r\n";
  41.                    $this->headers .= 'Content-Type: text/html; charset="utf-8"'."r\n";
  42.                } else {
  43.                    $_boundary = '==MP_Bound_xyccr948x==';
  44.                    $this->headers = 'MIME-Version: 1.0'."r\n";
  45.                    $this->headers = 'Content-type: multipart/alternative; boundary='.$_boundary."r\n";
  46.                    
  47.                    $this->message = 'Jest to komunikat wieloczęściowy w formacie MIME\n';
  48.                    $this->message .= "--$_boundary\n";
  49.                    $this->message .= 'Content-Type: text/plain; charset="utf-8"'."\n";
  50.                    $this->message .= 'Content-Transfer-Encoding: 8bit'."\n\n";
  51.                    $this->message .= $this->body."\n";
  52.                    $this->message .= "--$_boundary\n";
  53.                    $this->message .= 'Content-Type: text/html; charset="utf-8'."\n";
  54.                    $this->message .= 'Content-Transfer-Encoding: 8bit\n\n';
  55.                    $this->message .= $this->htmlbody."\n";
  56.                    $this->message .= "--$_boundary--";
  57.                }
  58.            }
  59.            
  60.            if (!mail($this->to, $this->subject, $this->message, $this->headers)) {
  61.                throw new Exception('Nieudane wysłanie listu email.');
  62.                return FALSE;
  63.            } else {
  64.                return TRUE;
  65.            }
  66.        }
  67.    }
  68. ?>


A nastepnie kruciótki skrypt aby przetestowac poprawnosć działania
  1. <?php
  2.  
  3.    require 'class.SimpleMail.php';
  4.    
  5.    $postcard = new SimpleMail();
  6.    
  7.    $postcard->to = "matewilk@gmail.com";
  8.    $postcard->subject = "Testowanie poczty z uzyciem html";
  9.    $postcard->body = "Test z użyciem tekstu HTML!";
  10.    $postcard->send_html = TRUE;
  11.    $postcard->send_text = FALSE;
  12.    
  13.    if($postcard->send()) {
  14.        echo "Udane wysłanie listu html!";
  15.    }
  16. ?>


Niestety gdy sprawdzam maila nie dochodzi wogole html tylko pusta wiadomość z tytułem, gdy uzywam skryptu do przesyłania tylko plain text wszystko jest ok, bład wystepuje przy przesylaniu html, mniemam ze bład jest gdzies w klasie SimpleMail tylko nie mam pojecia gdzie.....
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 Aktualny czas: 22.08.2025 - 00:48