send files to the mail with php

0

I have a form where all the data that you insert is sent to an email. I added a section so that you can upload images ect .. But when it is sent, the images are not sent, I get the following in the mail:

Imagenes: Array.

This my html

<label for="file-es" role="button">Seleccionar Archivos</label>
                <input id="file-es" name="file_es[]" type="file" multiple>
                <SMALL class="form-text text-muted">Sube aqui las imagenes para que podamos verlas.Maximo de 5.</SMAL>
                <div class="container-contact100-form-btn">

and the php is as follows:

<?php

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$portal = $_POST['portal'];
$piso = $_POST['piso'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$incidencia = $_POST['incidencia'];
$message = $_POST['message'];
$file_es[] = $_POST['file_es'];


$to = "[email protected]";
$email_subject ="Incidencia : ". $incidencia .".";
$email_body ="Hola esto es un correo generado con una web\n\nNombre: ".$first_name."\nApellido: ".$last_name."\nPortal: ".$portal."\nPiso: ".$piso."\nEmail: ".$email."\nTelefono: ".$phone."\nIncidencia: ".$incidencia."\nMensaje: ".$message."\nImagenes: ".$file_es.".";
$headers = "From: $email \r\n";

  mail($to,$email_subject,$email_body,$headers);
  header("Location: index.html");
?>
    
asked by francisco 22.03.2018 в 12:26
source

1 answer

0

In your form, the input with which you allow the user to attach images, is an array ( array ). Then, in the PHP reception of the form data, you receive the data from the array $_POST , when it should be from $_FILES . Otherwise, add the variable in a text string (what you do by concatenating it in the body of the email) returns what you actually received: an array ( Array() ). I suggest you make the change that I say ( $_FILES instead of $_POST ), and that if you are going to attach the images as files, investigate how it can be achieved using mail() of PHP (which is the method you are using) .

  

By the way, in HTML it is necessary to apply the brackets to name of the form field, but once in PHP, you no longer need to write them down. PHP understands that if the name has brackets, it is an arrangement, and receives it as such. In that case, when you receive the file fix, just $file_es = $_FILES["file_es"] . I suggest you do print_r($_POST) and print_r($_FILES) when receiving the data, to know what you received effectively, and how .

    
answered by 22.03.2018 в 12:49