2016-12-17 4 views
-1

ファイルアップロードのフォームがあります。フォームが送信された後、ファイルを電子メールで送信する必要があります。私は単純なPHPスクリプトを使用していますが、動作しません。アップロードされたファイルを電子メールの添付ファイルとして送信します。

アップロードしたファイルを電子メールで送信するにはどうすればよいですか?

//Send Mail 
     $file_tmp_name = $_FILES['file']['tmp_name']; 
    $file_name = $_FILES['file']['name']; 
    $file_size = $_FILES['file']['size']; 
    $file_type = $_FILES['file']['type']; 

//read from the uploaded file & base64_encode content for the mail 
     $handle = fopen($file_tmp_name, "r"); 
     $content = fread($handle, $file_size); 
     fclose($handle); 
     $encoded_content = chunk_split(base64_encode($content)); 


     $boundary = md5("sanwebe"); 
     //header 
     $headers = "MIME-Version: 1.0\r\n"; 
     $headers .= "From:".$mail."\r\n"; 
     $headers .= "Reply-To: ".$mail."" . "\r\n"; 
     $headers .= "Content-Type: multipart/mixed; boundary = ".$boundary."\r\n\r\n"; 

     //plain text 
     $body = "--".$boundary."\r\n"; 
     $body .= "Content-Type: text/plain; charset=ISO-8859-1\r\n"; 
     $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
     $body .= chunk_split(base64_encode($message)); 

     //attachment 
     $body .= "--".$boundary."\r\n"; 
     $body .="Content-Type: ".$file_type."; name=".$file_name."\r\n"; 
     $body .="Content-Disposition: attachment; filename=".$file_name."\r\n"; 
     $body .="Content-Transfer-Encoding: base64\r\n"; 
     $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
     $body .= $encoded_content; 


     send_mail($to,$subject,$body,$headers); 

答えて

0

あなたのフォームにはenctype='multipart/form-data'パラメータがありますか? 例:<form name="form_name" action="send.php" method="post" enctype='multipart/form-data'>

+0

はい私はenctypeを持っています – Siddhu

関連する問題