I have a contact form that should send an attachment, the problem is that it does not send the mail or the file, I have already looked at spam and others and I have no idea why it is not sent, try it with emails from Gmail and Hotmail and just do not send them.
PHP:
<?php
if(isset($_POST['submit'])) {
//Para y asunto del mensaje a enviar
$email_to = "[email protected]";
$email_subject = "Cotización de pagina Web";
//variables para los campos
$tipo = $_POST['tipo']; // required
$Colores = $_POST['Colores']; // required
$Medida = $_POST['Medida']; // required
$nombre = $_POST['Nombre']; // required
$telefono = $_POST['telefono']; // required
$email_from = $_POST['email']; // required
//variables para los datos del archivo
$nombrearchivo = $_FILES['archivo']['name'];
$archivo = $_FILES['archivo']['tmp_name'];
// Leemos el archivo a adjuntar
$archivo = file_get_contents($archivo);
$archivo = chunk_split(base64_encode($archivo));
// Cuerpo del Email
$message = "Nombre: ".$nombre ."\n\n".
"telefono: ". $telefono."\n\n" .
"Correo: " . $email_from. "\n\n" .
"Medida: " . $Medida. "\n\n" .
"Colores: " . $Colores. "\n\n" .
"Durabilidad: " . $tipo . "\n\n" .
$_POST['message'];
//cabecera del email (forma correcta de codificarla)
$headers = "From:" . $email_from ."\r\n";
'Reply-To:'.$email_from ."\r\n";
'X-Mailer:PHP/'.phpversion();
//armando mensaje del email
$message = "--=A=G=R=O=\r\n";
$message .= "Content-type:text/plain; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= $CuerpoMensaje . "\r\n\r\n";
//archivo adjunto para email
$email_message .= "--=A=G=R=O=\r\n";
$email_message .= "Content-Type: application/octet-stream; name=\"" . $nombrearchivo . "\"\r\n";
$email_message .= "Content-Transfer-Encoding: base64\r\n";
$email_message .= "Content-Disposition: attachment; filename=\"" . $nombrearchivo . "\"\r\n\r\n";
$email_message .= $archivo . "\r\n\r\n";
$email_message .= "--=A=G=R=O=--";
mail($email_to,$message,$headers) ;
}
?>
HTML:
<form action="email-form.php" method="post">
<div class="dropdown">
<label>
Seleccione el tipo de tapete
</label>
<select name="tipo[]">
<option value="premier">
Premier
</option>
<option value="comercial">
Comercial
</option>
<option value="promocional">
Promocional
</option>
</select>
</div>
<br>
<div class="input-field">
<input type="text" name="Colores" class="form-control" placeholder="Medida Base por Altura">
</div>
<div class="input-field">
<input type="text" name="Medida" class="form-control" placeholder="Color Fondo/Logotipo">
</div>
<div class="input-field">
<input type="text" name="Nombre" class="form-control" placeholder="Nombre">
</div>
<div class="input-field">
<input type="text" name="telefono" class="form-control" placeholder="Teléfono">
</div>
<div class="input-field">
<input type="email" name="email" class="form-control" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputFile">Archivo NO mayor a 2 MB</label>
<input type="file" name="archivo" id="exampleInputFile">
</div>
<button type="submit" id="submit" class="btn btn-blue btn-effect">Enviar</button>
<p class="aviso">Al dar click en el botón de Enviar, usted acepta nuestras <a href="aviso-de-privacidad.html">politicas de privacidad</a></p>
</form>