Hello, I have a system that sends mails with attachments but only works with a file, that is, it just sends a file.
this is my html code
<form id="" class="form" name="sentMessage" action='php/enviar_cv.php' method='post' target='_self' enctype="multipart/form-data" > <!-- form wrapper -->
<div class="row"> <!-- nested inner row -->
<!-- Input your name -->
<div class="col-md-4">
<div class="form-group"> <!-- Your name input -->
<input type="text" autocomplete="off" class="form-control" name="nombre" placeholder="Nombre *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<!-- Input your email -->
<div class="col-md-4">
<div class="form-group"> <!-- Your email input -->
<input type="email" autocomplete="off" class="form-control" name="email" placeholder="Correo Electróncio *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<!-- Input your Phone no. -->
<div class="col-md-4">
<div class="form-group"> <!-- Your email input -->
<input type="text" autocomplete="off" class="form-control" name="telefono" placeholder="Teléfono (s) *" id="phone" required data-validation-required-message="Please enter your phone no.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-12">
<div class="form-group"> <!-- Your email input -->
<input type="text" autocomplete="off" name="asunto" class="form-control" placeholder="Asunto" id="asunto" >
<p class="help-block text-danger"></p>
</div>
</div>
</div><!-- end nested inner row -->
<!-- Message Text area -->
<div class="form-group"> <!-- Your email input -->
<textarea class="form-control" rows="7" placeholder="Mensaje" name="comentarios" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
<div id="success"></div>
</div>
<div class="col-md-12">
<p style="float:left"><b>Si deseas asesoria inmediata adjunta tus archivos:</b>
<input type='file' name='archivo1' id='archivo1' multiple="multiple"/></p>
<button type="submit" class="btn btn-primary tf-btn color">Enviar</button> <!-- Send button -->
</div>
</form>
and this is my php code:
function form_mail($sPara, $sAsunto, $html, $sDe){
$bHayFicheros = 0;
$sCabeceraTexto = "";
$sAdjuntos = "";
if ($sDe)
$sCabeceras = "From:".$sDe."\n";
else
$sCabeceras = "";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$sCabeceras .= "MIME-version: 1.0\n";
$sCabeceras .= "Content-type: multipart/mixed;";
$sCabeceras .= "boundary=\"{$mime_boundary}\"\n";
$sCabeceras .= "Content-transfer-encoding: 7BIT\n";
$body_top = "--{$mime_boundary}\n";
$body_top .= "Content-type: text/html\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$sTexto = $body_top.$html;
//if ($bHayFicheros)
foreach ($_FILES as $vAdjunto){
if ($vAdjunto["size"] > 0){
$sAdjuntos .= "\n\n--{$mime_boundary}\n";
$sAdjuntos .= "Content-type: ".$vAdjunto["type"].";name=\"".$vAdjunto["name"]."\"\n";;
$sAdjuntos .= "Content-Transfer-Encoding: BASE64\n";
$sAdjuntos .= "Content-disposition: attachment;filename=\"".$vAdjunto["name"]."\"\n\n";
$oFichero = fopen($vAdjunto["tmp_name"], 'r');
$sContenido = fread($oFichero, filesize($vAdjunto["tmp_name"]));
$sAdjuntos .= chunk_split(base64_encode($sContenido));
fclose($oFichero);
}
}
$sTexto .= $sAdjuntos."\n\n";
return mail($sPara,$sAsunto,$sTexto,$sCabeceras);
}
if (form_mail("[email protected]", $asunto, $body, "[email protected]"));}