Napisalem sobie taka prostą funkcje do przesyłania maili :
<?php class SimpleMail { public $to = NULL; public $cc = NULL; public $bcc = NULL; public $from = NULL; public $subject = ''; public $body = ''; public $htmlbody = ''; public $send_text = TRUE; public $send_html = FALSE; private $message = ''; private $headers = ''; public function send ($to = NULL, $subject = NULL, $message = NULL, $headers = NULL) { $this->to = $to; $this->subject = $subject; $this->message = $message; if ($headers) { $this->headers = $headers; } } else { if ($this->from) { $this->headers .= 'From: '.$this->from."r\n"; } if ($this->cc) { $this->headers .= 'Cc: '.$this->cc."r\n"; } if ($this->bcc) { $this->headers .= 'Bcc: '.$this->bcc."r\n"; } if ($this->send_text and !$this->send_html) { $this->message = $this->body; } elseif ($this->send_html and !$this->send_text) { $this->message = $this->htmlbody; $this->headers .= "MIME-Version: 1.0r\n"; $this->headers .= 'Content-Type: text/html; charset="utf-8"'."r\n"; } else { $_boundary = '==MP_Bound_xyccr948x=='; $this->headers = 'MIME-Version: 1.0'."r\n"; $this->headers = 'Content-type: multipart/alternative; boundary='.$_boundary."r\n"; $this->message = 'Jest to komunikat wieloczęściowy w formacie MIME\n'; $this->message .= "--$_boundary\n"; $this->message .= 'Content-Type: text/plain; charset="utf-8"'."\n"; $this->message .= 'Content-Transfer-Encoding: 8bit'."\n\n"; $this->message .= $this->body."\n"; $this->message .= "--$_boundary\n"; $this->message .= 'Content-Type: text/html; charset="utf-8'."\n"; $this->message .= 'Content-Transfer-Encoding: 8bit\n\n'; $this->message .= $this->htmlbody."\n"; $this->message .= "--$_boundary--"; } } throw new Exception('Nieudane wysłanie listu email.'); return FALSE; } else { return TRUE; } } } ?>
A nastepnie kruciótki skrypt aby przetestowac poprawnosć działania
<?php require 'class.SimpleMail.php'; $postcard = new SimpleMail(); $postcard->to = "matewilk@gmail.com"; $postcard->subject = "Testowanie poczty z uzyciem html"; $postcard->body = "Test z użyciem tekstu HTML!"; $postcard->send_html = TRUE; $postcard->send_text = FALSE; if($postcard->send()) { } ?>
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.....