Hola muy buenas, estoy haciendo una página web en la que necesito un formulario en el cual los visitantes puedan adjuntar una foto y que el formulario llegue a mi correo. Todo me llega correctamente menos el archivo adjunto, voy a utilizar PHPMailer pero no se donde puedo colocar el código PHPMailer en mi formulario. Por favor que alguien me ayude.
Esta es mi formulario en HTML con el código PHP que me lo manda al correo:
Código PHP:
<?php
if (!isset($_POST['email'])) {
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
<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{
$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'];
$destino= "[email protected]";
$remitente = $_POST['email'];
$asunto = "Mensaje enviado por: ".$_POST['nombre'];
mail($destino,$asunto,$mensaje,"FROM: $remitente");
echo "Muchas gracias, datos enviados";
?>
<?php
}
?>
el problema viene con el codigo PHPMailer que no se si es correcto ni donde debo colocarlo
Código PHP:
<?php
include_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->From = "[email protected]";
$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->AddAddress("[email protected]", "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Gracias anticipadas!