Füllen, php Formular --> upload-Datei ---> senden Sie E-mail mit Anhang

Ich weiß, diese Frage wurde schon mehrfach gefragt, aber ich fand keine funktionierende Antwort.

Wie der Titel sagt, habe ich ein php-Formular mit input-Datei-Typ auf "Absenden", alle Daten werden per E-Mail inklusive Datei-Anhang, warum kann ich funktionierendes Skript.

Bitte helfen.

Aktualisierung meiner Antwort

$fileatt  = $_FILES['uploadfile']['tmp_name'];
$fileatt_type = $_FILES['uploadfile']['type'];
$fileatt_name = $_FILES['uploadfile']['name'];


$subject = "Some Subject goes here";
$uploadedfile = $_FILES['uploadfile']['name'];
$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers .= "Content-Type: application/octet-stream; name=\"".$fileatt_name."\"\r\n";
$headers .=  "Content-Transfer-Encoding: base64\r\n";




    //create a boundary string. It must be unique
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

      //Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";

     if (is_uploaded_file($fileatt)) {
      //Read the file to be attached ('rb' = read binary)
      $file = fopen($fileatt,'rb');
      $data = fread($file,filesize($fileatt));
      fclose($file);

      //Base64 encode the file data
      $data = chunk_split(base64_encode($data));  
     }
//begin of HTML message 
$message ="This is a multi-part message in MIME format.\n\n";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$message .= "--{$mime_boundary}\n" .
                  "Content-Type: {$fileatt_type};\n" .
                  " name=\"{$fileatt_name}\"\n" .
                  //"Content-Disposition: attachment;\n" .
                  //" filename=\"{$fileatt_name}\"\n" .
                  "Content-Transfer-Encoding: base64\n\n" .
                  $data . "\n\n" .
                  "--{$mime_boundary}--\n";
  • Es gibt viele Beispiele gerade durch die Suche hier auf stackoverflow - http://stackoverflow.com/search?q=php+form+file+upload+and+email
  • Was haben Sie versucht??
  • Ich habe versucht die PHP-E-mail, die ich erhalten eine verstümmelte Nachricht, keine klaren text ohne Inhalt
  • Stackoverflow funktioniert besser, wenn Sie nach Ihrem code, dass Sie versucht haben, und dann können wir helfen, gehen Sie durch, wie es zu lösen ist.
  • Ich aktualisiert meine Frage und den code Hinzugefügt. Dank
Schreibe einen Kommentar