Código PHP:
Ver original<?php
require_once('../class.phpmailer.php');
if (!isset($_POST['email'])) { ///Aqui debes canviar algo ?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
//// Cambia el action por el nombre del fichero, la constante tambien sirve...
<table border="5">
<tr>
<th width="217" scope="col">Nombre</th>
<th width="145" scope="col"><input type="text" name="nombre" id="nombre" /></th>
</tr>
<tr>
<th width="217">Apellidos</th>
<td width="145"><input type="text" name="apellidos" id="apellidos" /></td>
</tr>
<tr>
<th width="217" style="font-weight: bold">Teléfono</th>
<td width="145"><input type="text" name="telefono" id="telefono" /></td>
</tr>
<tr>
<th width="217">Localidad </th>
<td width="145"><input type="text" name="localidad" id="localidad" /></td>
</tr>
<tr>
<th width="217">C.P.</th>
<td width="145"><input type="text" name="cp" id="cp" /></td>
</tr>
<tr>
<th width="217">Provincia</th>
<td width="145"><input type="text" name="provincia" id="provincia" /></td>
</tr>
<tr>
<th width="217">Dirección</th>
<td width="145"><input type="text" name="direccion" id="direccion" /></td>
</tr>
<tr>
<th width="217">Comentario</th>
<td width="145"><textarea name="mensaje" id="mensaje" cols="16" rows="5"></textarea></td>
</tr>
<tr>
<th>Logotipo</th>
<td width="145"><label for="fileField"></label>
<input type="file" name="fileField" id="fileField" /></td>
</tr>
</table>
<p>
<label for="select"></label>
<label><br />
</label>
<label><br />
</label>
<input type="submit" value="Enviar" />
</p>
</form>
<?php
}else{
//////Porcesamos el mail///////////
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $mail->getFile('contents.html');
$mail->FromName = "First Last";
$mail->Subject = "PHPMailer Test Subject via mail()";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment Aqui debes adjuntar el fichero del cliente
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
////////////mostramos mensaje de cortesia//////////////
$mensaje="Mensaje del formulario de contacto";
$mensaje.= "\nNombre: ". $_POST['nombre'];
$mensaje.= "\nApellidos: ". $_POST['apellidos'];
$mensaje.= "\nTelefono: ". $_POST['telefono'];
$mensaje.= "\nLocalidad: ". $_POST['localidad'];
$mensaje.= "\nC.P.: ". $_POST['cp'];
$mensaje.= "\nProvincia: ". $_POST['provincia'];
$mensaje.= "\nDirección: ". $_POST['direccion'];
$mensaje.= "\nMensaje: \n".$_POST['mensaje'];
$remitente = $_POST['email'];
$asunto = "Mensaje enviado por: ".$_POST['nombre'];
mail($destino,$asunto,$mensaje,"FROM: $remitente"); echo "Muchas gracias, datos enviados";
/////////////////////////////////////////////////////////////////////
}
?>
<?php
}
?>
Sin corregirte el codigo lo que debes hacer es ponerlo en el propio fichero del formulario con un condicional que muestre el formulario si no recibe datos o procese el mail y muestre la respuesta si se ha llenado el formulario.
Yo cambiaria <?=$_SERVER['PHP_SELF']?> por el nombre del mismo fichero donde tienes el codigo....
if (!isset($_POST['email'])) {
el formulario no tiene ningun campo llamado email por lo que este condicional no te sirve para comprovar si debe mostrar el formulario o procesar el correo.
$mail->AddAttachment("images/phpmailer.gif"); esto efectivamente agrega un adjunto pero siempre el mismo "images/phpmailer.gif"... debes adjuntar el fichero elegido por el usuario ... que esta en $_FILES.
Repasa el
API de phpmailer para ver como debes hacerlo.