0

I have the following php code that correctly receives and sends information from a JS, and html form, along with a file attached, but now I want to add another attachment:

<?php
$name=$_POST["nombre"];
$email=$_POST["email"];
$tel=$_POST["tel"];
$tipcre=$_POST["tipcre"];
$tipemp=$_POST["tipemp"];
$ref1nom=$_POST["ref1nom"];
$ref1tel=$_POST["ref1tel"];
$ref1dir=$_POST["ref1dir"];
$ref1car=$_POST["ref1car"];
$ref2nom=$_POST["ref2nom"];
$ref2tel=$_POST["ref2tel"];
$ref2dir=$_POST["ref2dir"];
$ref2car=$_POST["ref2car"];

$archivoNombre=$_FILES['fichero']['name'];
$archivo=$_FILES['fichero']['tmp_name'];

$archivoNombre2=$_FILES['fichero2']['name'];
$archivo2=$_FILES['fichero2']['tmp_name'];

$archivo=file_get_contents($archivo); 
$archivo=chunk_split(base64_encode($archivo)); 
$uid=md5(uniqid(time())); 
$EmailTo="correo@electronico.com";
$Asunto="Documentación a través del Sitio WEB - ";
$Asunto.=$name;

$CuerpoMensaje='<html>
  <head><title>Documentación WEB</title></head>
  <body><h3>Se envía la siguiente información</h3>
  <strong>Nombre:</strong>';
$CuerpoMensaje.=$name;
$CuerpoMensaje.='<br><strong>E-mail: </strong>';
$CuerpoMensaje.=$email;
$CuerpoMensaje.='<br><strong>Teléfono: </strong>';
$CuerpoMensaje.=$tel;
$CuerpoMensaje.='<br><strong>Tipo de crédito: </strong>';
$CuerpoMensaje.=$tipcre;
$CuerpoMensaje.='<br><strong>Tipo de empleo: </strong>';
$CuerpoMensaje.=$tipemp;
$CuerpoMensaje.='<br><br><strong>Referencia personal 1: </strong>';
$CuerpoMensaje.=$ref1nom;
$CuerpoMensaje.='<br><strong>Teléfono: </strong>';
$CuerpoMensaje.=$ref1tel;
$CuerpoMensaje.='<br><strong>Dirección: </strong>';
$CuerpoMensaje.=$ref1dir;
$CuerpoMensaje.='<br><strong>Cargo: </strong>';
$CuerpoMensaje.=$ref1car;
$CuerpoMensaje.='<br><br><strong>Referencia personal 2: </strong>';
$CuerpoMensaje.=$ref2nom;
$CuerpoMensaje.='<br><strong>Teléfono: </strong>';
$CuerpoMensaje.=$ref2tel;
$CuerpoMensaje.='<br><strong>Dirección: </strong>';
$CuerpoMensaje.=$ref2dir;
$CuerpoMensaje.='<br><strong>Cargo: </strong>';
$CuerpoMensaje.=$ref2car;
$CuerpoMensaje.='<br><br>Se anexa la documentación<br>
  </body>
  </html>';
// para el envío en formato HTML 
$headers="MIME-Version: 1.0\r\n";
$headers.="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n";

$headers.="From: Documentación WEB <correo@electronico.com>\r\n";

$headers.="Reply-To:".$email."\r\n";

$headers.="Return-path:";
$headers.=$mail;
$headers.="\r\n";

$headers.="Cc: correo@electronico.com\r\n";

$headers.="Bcc: correo@electronico.com\r\n";

$mensaje="--".$uid."\r\n";
$mensaje.="Content-type:text/html; charset=utf-8\r\n";
$mensaje.="Content-Transfer-Encoding: 7bit\r\n";
$mensaje.=$CuerpoMensaje."\r\n";
$mensaje.="--" . $uid . "\r\n";
$mensaje.="Content-Type: application/octet-stream; 
  name=\"".$archivoNombre."\"\r\n";
$mensaje.="Content-Transfer-Encoding: base64\r\n";
$mensaje.="Content-Disposition: attachment; 
  filename=\"".$archivoNombre."\"\r\n";
$mensaje.=$archivo."\r\n";
$mensaje.="--".$uid."--";


$success=mail($EmailTo, $Asunto, $mensaje, $headers);


if($success){
 echo "success";
}else{
 echo "invalid";
}
?>

The file is entered in another input and received in the variable fichero2 like this:

$archivoNombre2=$_FILES['fichero2']['name'];
$archivo2=$_FILES['fichero2']['tmp_name'];

What should I do to attach it and send them two attachments?

Note, I do not need to validate it or use phpmailer, nor check whether they are two files, or anything else. I already do in a JavaScript file.

  • Possible duplicate of [Send attachments with PHP Mail()?](https://stackoverflow.com/questions/12301358/send-attachments-with-php-mail) the important point there is to use PHPMailer –  Nov 27 '17 at 21:48
  • I want to do it myself, without plugins or third-party files. Sure are three or four lines of code what will serve me for other things later. I already sent a file without problem, I need to send another one that enters by another input, nothing more. – Leonardo Tinoco Acero Nov 27 '17 at 22:06

0 Answers0