Witam
Mam problem z załącznikiem w meilu.
1. mianowicie widzę że załącznik jest jednak podczas otwierania go jest jakiś błąd i nie można go otworzyć.
2. jak zrobić aby można było przesłać dowolny typ pliku np. pdf, doc itp a nie tylko jak mam do tej pory jpg
3. jak ustawić w tej funkcji kodowanie polskich znaków dla treści

Oto moja funkcja:

  1. $target_path = basename( $_FILES['file']['name'] );
  2. if($target_path){
  3. $fileatt = $target_path; //sciezka do pliku
  4. $fileatt_type = "image/jpg"; // typ zalacznika
  5.  
  6. $fileatt_name = $target_path; // nazwa zalacznika
  7.  
  8. $email_from = $email_who; // Who the email is from
  9. $email_subject = $nr_rma; // The Subject of the email
  10. //$email_txt = "fdsadfasfdas"; // Message that the email has in it
  11.  
  12. $email_to = $email_customer; // Who the email is too
  13.  
  14. $headers = "From: " . $first_last_name . "<" . $email_who . ">";
  15.  
  16. $file = fopen($fileatt,'rb');
  17. $data = fread($file,filesize($fileatt));
  18. fclose($file);
  19.  
  20. $semi_rand = md5(time());
  21. $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  22.  
  23. $headers .= "\nMIME-Version: 1.0\n" .
  24. "Content-Type: multipart/mixed;\n" .
  25. " boundary=\"{$mime_boundary}\"";
  26.  
  27. $email_message .= "This is a multi-part message in MIME format.\n\n" .
  28. "MIME-Versio: 1.0r\n"."Content-type: text/html; charset=UTF-8\r\n" .
  29. "--{$mime_boundary}\n" .
  30.  
  31. "Content-Transfer-Encoding: 7bit\n\n" .
  32. $email_message . $text_to_client ."\n\n";
  33.  
  34. $data = chunk_split(base64_encode($data));
  35.  
  36. $email_message .= "--{$mime_boundary}\n" .
  37. "Content-Type: {$fileatt_type};\n" .
  38. " name=\"{$fileatt_name}\"\n" .
  39. "Content-Disposition: attachment;\n" .
  40. " filename=\"{$fileatt_name}\"\n" .
  41. "Content-Transfer-Encoding: base64\n\n" .
  42. $data . "\n\n" .
  43. "--{$mime_boundary}--\n";
  44. $email_message .= "";
  45. mail($email_to, $email_subject, $email_message, $headers);
  46. }