Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Email z zalacznikiem
Forum PHP.pl > Forum > PHP
Spyder
Witam mam taki kod

  1. <?php
  2. /* Mailer with Attachments */
  3.  
  4. $action = $_REQUEST['action'];
  5. global $action;
  6.  
  7. function showForm() {
  8. ?>
  9.  
  10. <form enctype="multipart/form-data" name="send" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  11. <input type="hidden" name="action" value="send" />
  12. <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
  13. <p>Recipient Name: <input name="to_name" size="50" />
  14. Recipient Email: <input name="to_email" size="50" />
  15. From Name: <input name="from_name" size="50" />
  16. From Email: <input name="from_email" size="50" />
  17. Subject: <input name="subject" size="50" />
  18. Message: <textarea name="body" rows="10" cols="50"></textarea>
  19. Attachment: <input type="file" name="attachment" size="50" />
  20. <input type="submit" value="Send Email" /></p>
  21.  
  22. <?php
  23. }
  24.  
  25. function sendMail() {
  26. if (!isset ($_POST['to_email'])) { //Oops, forgot your email addy!
  27. die ("<p>Oops! You forgot to fill out the email address! Click on the back arrow to go back</p>");
  28. }
  29. else {
  30. $to_name = stripslashes($_POST['to_name']);
  31. $from_name = stripslashes($_POST['from_name']);
  32. $subject = stripslashes($_POST['subject']);
  33. $body = stripslashes($_POST['body']);
  34. $to_email = $_POST['to_email'];
  35. $attachment = $_FILES['attachment']['tmp_name'];
  36. $attachment_name = $_FILES['attachment']['name']; 
  37. if (is_uploaded_file($attachment)) { //Do we have a file uploaded?
  38. $fp = fopen($attachment, "rb"); //Open it
  39. $data = fread($fp, filesize($attachment)); //Read it
  40. $data = chunk_split(base64_encode($data)); //Chunk it up and encode it as base64 so it can emailed
  41. fclose($fp);
  42. }
  43. //Let's start our headers
  44. $headers = "From: $from_name<" . $_POST['from_email'] . ">\n";
  45. $headers .= "Reply-To: <" . $_POST['from_email'] . ">\n"; 
  46. $headers .= "MIME-Version: 1.0\n";
  47. $headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n"; 
  48. $headers .= "X-Sender: $from_name<" . $_POST['from_email'] . ">\n";
  49. $headers .= "X-Mailer: PHP4\n";
  50. $headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
  51. $headers .= "Return-Path: <" . $_POST['from_email'] . ">\n"; 
  52. $headers .= "This is a multi-part message in MIME format.\n";
  53. $headers .= "------=MIME_BOUNDRY_main_message \n"; 
  54. $headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n"; 
  55.  
  56. $message = "------=MIME_BOUNDRY_message_parts\n";
  57. $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; 
  58. $message .= "Content-Transfer-Encoding: quoted-printable\n"; 
  59. $message .= "\n"; 
  60. /* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
  61. $message .= "$body\n";
  62. $message .= "\n"; 
  63. $message .= "------=MIME_BOUNDRY_message_parts--\n"; 
  64. $message .= "\n"; 
  65. $message .= "------=MIME_BOUNDRY_main_message\n"; 
  66. $message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n";
  67. $message .= "Content-Transfer-Encoding: base64\n";
  68. $message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
  69. $message .= $data; //The base64 encoded message
  70. $message .= "\n"; 
  71. $message .= "------=MIME_BOUNDRY_main_message--\n"; 
  72.  
  73. // send the message
  74. mail("$to_name<$to_email>", $subject, $message, $headers); 
  75. print "Mail sent. Thank you for using the MyNewName5333 Mailer.";
  76. }
  77. }
  78.  
  79. ?>
  80.  
  81. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  82. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  83. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  84. <head>
  85. ****** http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  86. <style="css" type="text/css">
  87. <!--
  88. body {
  89. margin: 0px;
  90. font-family: Verdana, Arial, Helvetica, sans-serif;
  91. font-size: 12px;
  92. }
  93. a {color: #0000ff}
  94. -->
  95. </style>
  96. </head>
  97. <body>
  98.  
  99. <?php
  100. switch ($action) {
  101. case "send":
  102. sendMail();
  103. showForm();
  104. break;
  105. default:
  106. showForm();
  107. }
  108. ?>
  109.  
  110. </body>
  111. </html>


I ogolnie dziala to niezle zalacznik jest dolanczany lecz nie tekst zmienna $body questionmark.gif? Doszedlem ze jest to zwiazane z ta linijka:

$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";

a dokladnie z Content-Type: multipart/related; jak zmienie to na text/plain to zalaczy mi tekst ale juz nie zalacznik ?

Czy ktos wie w czym moze bycproblem questionmark.gif? Dziêki
nospor
Cytat
I ogolnie dziala to niezle zalacznik jest dolanczany lecz nie tekst zmienna $body
A po polsku? S³ysza³ o znakach interpunkycjnych oraz ogólnie o pisaniu tak jakby sie komus próbowa³o opisac cos? Bo niby co to znaczy: lecz nie tekst zmienna $body ?
Próbuj±c jednak to roszyfrowac doszedlem do tego, ze zalacznik ci sie wysyla, ale tekst ze zmiennej $body juz nie. Dobrze zgadlem?

uzyj klasy PHPMailer i juz nigdy wiecej w zadne headery bawiæ siê nie bedziesz.
Spyder
Sorki ogolnie mam taka odp na innym forum:

If you send mail to a regular POP3 it works, but if you send mail to Yahoo! or GMail it only sends the attachment? That's what I think you said, but I am not sure.

POP3 = Body & Attachment.
Yahoo! = Attachment only.
GMail = Attachment only.

Czyli sparawa z konfiguracja POP3
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.