Witam, mam problem z generowaniem maili z załącznikiem. Chcę wysłac wizytówkę "*.vcf" za każdym razem wysłania formularza kontaktowego.
Jeśli tekst jest wpisany statycznie i nie ma zadeklarowanych zmiennych php, to po przyjściu maila jest tak jak powinno byc - wiadomośc + załącznik.
Jeśli natomiast dodam pierwsze 16 linijek poniższego kodu, to zamiast tworzyc maila z załącznikiem, przesyła mi maila z kodem źródłowym, bez załącznika.
Bez względu czy ustawię kodowanie strony na ANSI czy utf8 zawsze jest tak samo.
W czym tkwi błąd i jak go naprawic?

Oto kod:
  1. <?php
  2. //session_start();
  3. include('funkcje.php');
  4. //$db=polaczMy();
  5. $nazwa = $_POST['nazwa'];
  6. $vorname= $_POST['vorname'];
  7. $strasse = $_POST['strasse'];
  8. $kod = $_POST['kod'];
  9. $tel = $_POST['tel'];
  10. $mail = $_POST['mail'];
  11. $datum_od = $_POST['datum_od'];
  12. $datum_to = $_POST['datum_to'];
  13. $ort = $_POST['ort'];
  14. $zeit = $_POST['zeit'];
  15. $mietteilung = $_POST['mietteilung'];
  16. $service = $_POST['service'];
  17.  
  18.  
  19. $to = 'jakis@mail.com';
  20. $subject = 'Anfrage';
  21. $random_hash = md5(date('r', time()));
  22. $headers = "From: xxx r\n";
  23. $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
  24. $attachment = "BEGIN:VCARD
  25. VERSION:3.0
  26. N:".$vorname.";;;;
  27. FN:".$vorname."
  28. ORG:".$nazwa."
  29. ADR;TYPE=work:;;".$strasse.";".$ort.";;;
  30. EMAIL;type=INTERNET;type=WORK;type=internet:".$mail."
  31. TEL;type=WORK;type=pref:".$tel."
  32. END:VCARD";
  33.  
  34.  
  35. ?>
  36. --PHP-mixed-<?php echo $random_hash; ?>
  37. Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
  38.  
  39. --PHP-alt-<?php echo $random_hash; ?>
  40. Content-Type: text/plain; charset="iso-8859-1"
  41. Content-Transfer-Encoding: 7bit
  42.  
  43. Hello World!!!
  44. This is simple text email message.
  45.  
  46. --PHP-alt-<?php echo $random_hash; ?>
  47. Content-Type: text/html; charset="iso-8859-1"
  48. Content-Transfer-Encoding: 7bit
  49.  
  50. <h2>Hello World!</h2>
  51. <p>This is something with <b>HTML</b> formatting.</p>
  52.  
  53. --PHP-alt-<?php echo $random_hash; ?>--
  54.  
  55. --PHP-mixed-<?php echo $random_hash; ?>
  56. Content-Type: text/vcard; name="attachment.vcf"
  57. Content-Transfer-Encoding: 7bit
  58. Content-Disposition: attachment
  59.  
  60. <?php echo $attachment; ?>
  61. --PHP-mixed-<?php echo $random_hash; ?>--
  62.  
  63. <?php
  64. //copy current buffer contents into $message variable and delete current output buffer
  65. $message = ob_get_clean();
  66. //send the email
  67. $mail_sent = @mail( $to, $subject, $message, $headers );
  68. //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
  69. echo $mail_sent ? "Mail sent" : "Mail failed";
  70. ?>


Pozdrwiam