2012-01-17 13 views
0

私はこの簡単なphpメールフォームを持っています。それは働いて、私は私のフォームを作るために使用することができますが、私は問題があります:このメールフォームへの添付ファイルの追加

私はこのフォームに2つまたは3つの添付ファイルを追加したいと思います。私はphp.netでメールについてたくさんの読書を試みましたが、私は自分でそれをすることはできません。

<?php 
$name=$_POST['name']; 
$email=$_POST['email']; 
$address=$_POST['address']; 
$phone=$_POST['phone']; 
$fax=$_POST['fax']; 
$mobile=$_POST['mobile']; 
$subject=$_POST['subject']; 
$website=$_POST['website']; 
$message=$_POST['message']; 
$fulltext = " 
______________________________________________ 
| 
| This Is $name Information: 
|______________________________________________ 
| Name : $name 
|______________________________________________ 
| E-Mail : $email 
|______________________________________________ 
| Address : $address 
|______________________________________________ 
| Phone : $phone 
|______________________________________________ 
| FAX : $fax 
|______________________________________________ 
| Mobile : $mobile 
|______________________________________________ 
| Subject : $subject 
|______________________________________________ 
| Website : $website 
|______________________________________________ 
| Message : $message 
|______________________________________________ 
"; 
$to = '[email protected]'; 
$subject = 'Connect FORM <<'; 
$headers = 'From: [email protected]' . "\r\n" . 
$message = $fulltext; 

mail($to, $subject, $message, $headers); 
echo 'file ersal shod'; 
?> 

答えて

0

私はhttp://ru.php.net/manual/ru/function.mail.php#105661からコードを改善:

<?php 
function multi_attach_mail($to, $subject, $message, $files, $sendermail){ 
    // email fields: to, from, subject, and so on 
    $from = "Files attach <".$sendermail.">"; 
    //$subject = date("d.M H:i")." F=".count($files); 
    $message .= "\n".count($files)." attachments"; 
    $headers = "From: $from"; 

    // boundary 
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

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

    // multipart boundary 
    $message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 

    // preparing attachments 
    for($i=0;$i<count($files);$i++){ 
     if(is_file($files[$i])){ 
      $message .= "--{$mime_boundary}\n"; 
      $fp = @fopen($files[$i],"rb"); 
     $data = @fread($fp,filesize($files[$i])); 
        @fclose($fp); 
      $data = chunk_split(base64_encode($data)); 
      $message .= "Content-Type: application/octet-stream; name=\"".basename($files[$i])."\"\n" . 
      "Content-Description: ".basename($files[$i])."\n" . 
      "Content-Disposition: attachment;\n" . " filename=\"".basename($files[$i])."\"; size=".filesize($files[$i]).";\n" . 
      "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; 
      } 
     } 
    $message .= "--{$mime_boundary}--"; 
    $returnpath = "-f" . $sendermail; 
    $ok = @mail($to, $subject, $message, $headers, $returnpath); 
    if($ok){ return $i; } else { return 0; } 
    } 

multi_attach_mail("[email protected]", 
    "Subject of mail" , 
    "Hello world!!!", 
    array($_SERVER["DOCUMENT_ROOT"] . "/first.file", // one file in root of your site 
     $_SERVER["DOCUMENT_ROOT"] . "/second.file" // another one 
    ), 
    "[email protected]"); 
?> 
+0

:(プラザ私はこのコードをuderstand CANDもっと私を助ける:(( –

+0

使用 'multi_attach_mail'はあなたのコード サムシングで' mail'機能をinsteed multi_attach_mail($ $対象に、$メッセージ、アレイ( '/パス/に/ file1.ext'、 '/別/パス/ file2.ext';その '... $メッセージ= $のフルテキストなど)、 '[email protected]'); echo 'ファイルersal shod'; ' –

関連する問題