email - fopen multiple files to send mail with mail() php -
i have problems send mail multiple files mail() php. until now, send first file, need please. give code:
html:
<form action="colabora.php" method="post" enctype="multipart/form-data">
[...]
<div id="adjuntos"> <input type="file" name="archivos[]" class="form-control"/> </div>
[...]
php:
[...]
if (isset ($_files["archivos"])) { $tot = count($_files["archivos"]["name"]); ($i = 0; $i < $tot; $i++){ $_name=$_files["archivos"]["name"][$i]; $_type=$_files["archivos"]["type"][$i]; $_size=$_files["archivos"]["size"][$i]; $_temp=$_files["archivos"]["tmp_name"][$i]; //files exists if(strcmp($_name, "")){ $fp = fopen($_temp, "rb"); $file = fread($fp, $_size); $file = chunk_split(base64_encode($file)); } // files headers $headers .= "content-type:application/octet-stream "; $headers .= "name=\"".$_name."\"r\n"; $headers .= "content-transfer-encoding: base64\r\n"; $headers .= "content-disposition: attachment; "; $headers .= "filename=\"".$_name."\"\r\n\n"; $headers .= "".$file."\r\n"; $headers .= "--".$num."--"; } }
[...]
mail($para, $asunto, $body, $headers)
i've noted have lost boundary before each attachment.
// files headers $headers .= "--".$num."\r\n"; // boundary $headers .= "content-type:application/octet-stream "; $headers .= "name=\"".$_name."\"r\n"; $headers .= "content-transfer-encoding: base64\r\n"; $headers .= "content-disposition: attachment; "; $headers .= "filename=\"".$_name."\"\r\n\n"; $headers .= $file."\r\n";
the closing boundary (ended "--") should placed outside loop:
$headers .= "--".$num."--\r\n";
Comments
Post a Comment