In php how to compress attachments to mail and encrypt them?

2

Let's see I have the script in php, it works very well for me to send emails, but I would like to compress everything and encrypt them I have seen a library for this as (phpzip and ziparchive) or (php-encryption); And I do not get to include them there Please, if anybody knows about the subject, I am grateful

<?php

    $Nombre = $_POST['Nombre'];
    $Email = $_POST['Email'];
    $Mensaje = $_POST['Mensaje'];
    $Telefono = $_POST['Telefono'];
    $archivo = $_FILES['adjunto'];
    $archivo2 = $_FILES['adjunto2'];
    $archivo3 = $_FILES['adjunto3'];

    if ($Nombre=='' || $Email=='' || $Mensaje=='' || $Telefono==''){

     echo "<script>alert('Los campos marcados con * son obligatorios');location.href ='javascript:history.back()';</script>";

  }else{


require("archivosformulario/class.phpmailer.php");
$mail = new PHPMailer();

$mail->From     = $Email;
$mail->FromName = $Nombre; 
$mail->AddAddress("[email protected]"); // Dirección a la que llegaran los mensajes.

// Aquí van los datos que apareceran en el correo que reciba
//adjuntamos un archivo 


$mail->WordWrap = 50; 
$mail->IsHTML(true);     
$mail->Subject  =  "Contacto";
$mail->Body     =  "Nombre: $Nombre \n<br />".    
"Email: $Email \n<br />".    
"Mensaje: $Mensaje \n<br />".
"Telefono: $Telefono \n<br />";
$mail->AddAttachment($archivo['tmp_name'], $archivo['name']);
$mail->AddAttachment($archivo2['tmp_name'], $archivo2['name']);
$mail->AddAttachment($archivo3['tmp_name'], $archivo3['name']);



// Datos del servidor SMTP

$mail->IsSMTP(); 
$mail->Host = "ssl://smtp.gmail.com:465";  // Servidor de Salida.
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]";  // Correo Electrónico
$mail->Password = "pass"; // Contraseña

if ($mail->Send())
echo "<script>alert('Formulario enviado exitosamente, le responderemos lo más pronto posible.');location.href ='javascript:history.back()';</script>";
else
echo "<script>alert('Error al enviar el formulario');location.href ='javascript:history.back()';</script>";

}

?>
    
asked by andros77 04.10.2017 в 12:24
source

1 answer

1

Good morning.

To compress the files I would do something like this:

        $archive_file_name = 'ficheros.zip';
        $file_path = "C:\tmp\";

        $pathZip = $file_path . $archive_file_name;

        $zip = new ZipArchive();

        //Creamos el fichero
        if ($zip->open($pathZip, ZipArchive::CREATE)!==TRUE) {
            exit("cannot open <$archive_file_name>\n");
        }

        //Agregamos los ficheros en el zip
        foreach ($files_names as $file) {
            $dest = $file_path.$file;
            $zip->addFile($dest,$file);
        }

        $zip->close();

As for the encryption, what I would do would be to encrypt the contents of the files with openssl_encrypt . You can get more information here .

    
answered by 04.10.2017 / 16:35
source