Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] mail() z załącznikiem
janekpogwad
post
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 22.09.2008
Skąd: Wadowice

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


Witam,
przeszukałem już chyba cały internet i jakoś nie mogę sobie poradzić z takim problemem.

Chciałbym utworzyć formularz, za pomocą którego można by było dodać załącznik (już nie chodzi mi o automatyczny dobór MIME; wystarczy image/jpeg), który wysłałby się jako e-mail. Nie chce, żeby ów załącznik najpierw zapisywał się na dysku, a później z niego się wysyłał. Chciałbym coś w stylu jakiego tmp.

Jakieś pomysły?

Z góry dziękuję
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
dantes
post
Post #2





Grupa: Zarejestrowani
Postów: 29
Pomógł: 5
Dołączył: 22.09.2009

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


  1. <?php
  2. class m_Mail {
  3. var $to;
  4. var $subject;
  5. var $content;
  6. var $headers;
  7. var $marker;
  8. var $type;
  9. var $xMailer = "xMailer";
  10.  
  11. function eMail($type = "1", $from, $replyto)
  12. {
  13. $this->type = $type;
  14. $this->headers .= "From: " . $from . "\n";
  15. $this->headers .= "Reply-to: " . $replyto . "\n";
  16. $this->headers .= "X-Mailer: " . $this->xMailer . "\n";
  17. $this->headers .= "MIME-Version: 1.0\n";
  18. if ($type == 1) {
  19. $this->headers .= "Content-Type: text/html; charset=utf-8\n";
  20. } else {
  21. srand((double)microtime() * 1000000);
  22. $this->marker = md5(uniqid(rand()));
  23. $this->headers .= "Content-Type: multipart/mixed;\n";
  24. $this->headers .= "\tboundary=\"___" . $this->marker . "==\"\n\n";
  25. $this->content = "--___" . $this->marker . "==\n";
  26. $this->content .= "Content-Type: text/html; charset=\"utf-8\"\n";
  27. $this->content .= "Content-Transfer-Encoding: 8bit\n\n";
  28. }
  29. }
  30.  
  31. function eMailAttachment($mimeType, $fileName, $data)
  32. {
  33. if ($this->type != 1) {
  34. $this->content .= "\n\n--___" . $this->marker . "==\n";
  35. $this->content .= "Content-Type: " . $mimeType . "; name=\"" . $fileName . "\"\n";
  36. $this->content .= "Content-Transfer-Encoding: base64\n";
  37. $this->content .= "Content-Disposition: attachment; filename=\"" . $fileName . "\"\n\n";
  38. $this->content .= chunk_split(base64_encode($data));
  39. }
  40. }
  41.  
  42. function eMailSend($to)
  43. {
  44. if ($this->type != 1) {
  45. $this->content .= "--___" . $this->marker . "==--\n\n"; // close marker
  46. }
  47. mail ($to, $this->subject, $this->content, $this->headers);
  48. }
  49.  
  50. function eMailContent($subject, $content)
  51. {
  52. $this->subject = $subject;
  53. $this->content .= $content;
  54. }
  55. }
  56.  
  57. ?>


To jest klasa, którą wysyłam maile. Może Ci pomoże.
Autor:
http://www.kocjan.net/publikacje.html?id=5

edit:

chyba, że chodzi Ci o załączenie grafiki inline, bezpośrednio w wiadomości, a nie jako "załącznik" "załącznik". (IMG:style_emoticons/default/winksmiley.jpg)

Ten post edytował dantes 1.10.2009, 18:43:20
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: 26.12.2025 - 15:18