Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Skrypt do wysyłania powiadomien e-mail
Forum PHP.pl > Forum > Przedszkole
mckpea
witam, mam kod który ma wysyłać email z powiadomieniem, ale nie mogę sobie z nim poradzić cały czas skrypt wysyła mi w wiadomości warunki Content-Type w wew. wiadomości i ich nie interpretuje nie rozróżnia co jest text/plain a co text/html, załącznik wyświetlany jest w postaci binarnej, napewno coś robię źle tylko nie wiem co, proszę o pomoc oto kod:

  1.  
  2. <?php
  3.  
  4. $to = 'mymail@gmail.com';
  5.  
  6. $subject = 'Test.';
  7.  
  8. $random_hash = md5(time());
  9.  
  10. $headers = "From: Faktury \r\n Reply-To: księgowosc@domena.pl"."\r\n";
  11.  
  12. $headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""."\r\n";
  13.  
  14. $headers .= "MIME-Version: 1.0"."\r\n";
  15.  
  16. $attachment = chunk_split(base64_encode(file_get_contents('plik.jpg')));
  17.  
  18. ?>
  19. --PHP-mixed-<?php echo $random_hash; ?>
  20. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  21.  
  22. --PHP-alt-<?php echo $random_hash; ?>
  23. Content-Type: text/plain; charset="iso-8859-1"
  24. Content-Transfer-Encoding: 7bit
  25.  
  26. Hello World!!!
  27. This is simple text email message.
  28.  
  29. --PHP-alt-<?php echo $random_hash; ?>
  30. Content-Type: text/html; charset="iso-8859-1"
  31. Content-Transfer-Encoding: 7bit
  32.  
  33. <h2>Hello World!</h2>
  34. <p>This is something with <b>HTML</b> formatting.</p>
  35.  
  36. --PHP-alt-<?php echo $random_hash; ?>--
  37.  
  38. --PHP-mixed-<?php echo $random_hash; ?>
  39. Content-Type: image/jpg; name="logo_notemaster.jpg"
  40. Content-Transfer-Encoding: base64
  41. Content-Disposition: attachment; filename="logo_notemaster.jpg"
  42.  
  43. <?php echo $attachment; ?>
  44. --PHP-mixed-<?php echo $random_hash; ?>--
  45.  
  46. <?php
  47.  
  48. $message = ob_get_clean();
  49.  
  50. $mail_sent = @mail( $to, $subject, $message, $headers );
  51.  
  52. echo $mail_sent ? "Mail sent" : "Mail failed";
  53. ?>
  54.  
Rysh
Użyj klasy https://github.com/PHPMailer/PHPMailer
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.