En el formulario tengo la opción de enviar un archivo adjunto y en función de si lo adjunta o no, repito el mismo código.
Otro problema, es que en el asunto si me escribe los acentos y las ñ, pero en el mensaje no. Mirando por los foros cambié el contetn-type y me sigue sin funcionar.
Os dejo el código en php, que tengo. Gracias.
Código PHP:
<?php
session_start();
if( isset($_POST['name']) && strtoupper($_POST['captcha']) == $_SESSION['captcha_id'] )
{
$to = '[email protected]'; // Replace with your email
//$subject = 'Formulario Web'; // Replace with your $subject
$subject = $_POST['subject'];
if($subject==""){
$subject = 'Formulario Web';
}
//$headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];
$from = 'From: [email protected]'. "\r\n";
$reply = 'Reply-To: [email protected]';
$headers = $from.$reply.'X-Mailer: PHP/'.phpversion();
$message = 'Name: ' . $_POST['name'] . "\n" .
'E-mail: ' . $_POST['email'] . "\n" .
'Subject: ' . $_POST['subject'] . "\n" .
'Código Postal: ' . $_POST['codigo'] . "\n" .
'Teléfono: ' . $_POST['tlf'] . "\n" .
'Message: ' . $_POST['message'];
if( isset($_FILES['file']['tmp_name']) )
{
// Get a random 32 bit number.
$num = md5(time());
// Define the main headers.
//$headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=$num\r\n";
$headers .= "--$num\r\n";
// Define the message section
$headers .= "Content-Type: text/plain\r\n";
$headers .= "Content-Transfer-Encoding:8bit\r\n\n";
$headers .= "$message\r\n";
$headers .= "--$num\r\n";
// Read the file into a variable
$file = fopen($_FILES['file']['tmp_name'], 'r');
$size = $_FILES['file']['size'];
$content = fread($file, $size);
$encoded_content = chunk_split(base64_encode($content));
// Define the attachment section
$headers .= "Content-Type: ". $_FILES['file']['type'] ."; ";
$headers .= 'name="' . $_FILES['file']['name'] . '"' . "\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= 'filename="' . $_FILES['file']['name'] . '"' . "\r\n\n";
$headers .= "$encoded_content\r\n";
$headers .= "--$num--";
if( $_POST['copy'] == 'on' )
{
mail($_POST['email'], $subject, $message, $headers);
}
$from = 'From: ' . $_POST['email'] . "\r\n";
$reply = 'Reply-To: [email protected]';
$headers = $from.$reply.'X-Mailer: PHP/'.phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=$num\r\n";
$headers .= "--$num\r\n";
// Define the message section
$headers .= "Content-Type: text/plain\r\n";
$headers .= "Content-Transfer-Encoding:8bit\r\n\n";
$headers .= "$message\r\n";
$headers .= "--$num\r\n";
$headers .= "Content-Type: ". $_FILES['file']['type'] ."; ";
$headers .= 'name="' . $_FILES['file']['name'] . '"' . "\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= 'filename="' . $_FILES['file']['name'] . '"' . "\r\n\n";
$headers .= "$encoded_content\r\n";
$headers .= "--$num--";
mail($to, $subject, $message, $headers);
}
else {
if( $_POST['copy'] == 'on' )
{
mail($_POST['email'], $subject, $message, $headers);
}
$from = 'From: ' . $_POST['email'] . "\r\n";
$reply = 'Reply-To: [email protected]';
$headers = $from.$reply.'X-Mailer: PHP/'.phpversion();
mail($to, $subject, $message, $headers);
}
}
?>