Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/01/2013, 05:08
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 11 meses
Puntos: 574
Respuesta: Problema PHPMailer

Código PHP:
Ver original
  1. <?php
  2. require_once('../class.phpmailer.php');
  3.  
  4. if (!isset($_POST['email'])) {   ///Aqui debes canviar algo
  5. ?>            
  6.             <form action="<?=$_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data">
  7. //// Cambia el action por el nombre del fichero, la constante tambien sirve...
  8.               <table border="5">
  9.                 <tr>
  10.                   <th width="217" scope="col">Nombre</th>
  11.                   <th width="145" scope="col"><input type="text" name="nombre" id="nombre" /></th>
  12.                 </tr>
  13.                 <tr>
  14.                   <th width="217">Apellidos</th>
  15.                   <td width="145"><input type="text" name="apellidos" id="apellidos" /></td>
  16.                 </tr>
  17.                 <tr>
  18.                   <th width="217" style="font-weight: bold">Teléfono</th>
  19.                   <td width="145"><input type="text" name="telefono" id="telefono" /></td>
  20.                 </tr>
  21.                 <tr>
  22.                   <th width="217">Localidad </th>
  23.                   <td width="145"><input type="text" name="localidad" id="localidad" /></td>
  24.                 </tr>
  25.                 <tr>
  26.                   <th width="217">C.P.</th>
  27.                   <td width="145"><input type="text" name="cp" id="cp" /></td>
  28.                 </tr>
  29.                 <tr>
  30.                   <th width="217">Provincia</th>
  31.                   <td width="145"><input type="text" name="provincia" id="provincia" /></td>
  32.                 </tr>
  33.                 <tr>
  34.                   <th width="217">Dirección</th>
  35.                   <td width="145"><input type="text" name="direccion" id="direccion" /></td>
  36.                 </tr>
  37.                 <tr>
  38.                   <th width="217">Comentario</th>
  39.                   <td width="145"><textarea name="mensaje" id="mensaje" cols="16" rows="5"></textarea></td>
  40.                 </tr>
  41.                 <tr>
  42.                   <th>Logotipo</th>
  43.                   <td width="145"><label for="fileField"></label>
  44.                   <input type="file" name="fileField" id="fileField" /></td>
  45.                 </tr>
  46.               </table>
  47.               <p>
  48.                 <label for="select"></label>
  49.                 <label><br />
  50.                 </label>
  51.                 <label><br />
  52.                 </label>
  53.                 <input type="submit" value="Enviar" />
  54. </p>
  55.             </form>
  56. <?php
  57. }else{
  58.  
  59. //////Porcesamos el mail///////////
  60.  
  61. $mail             = new PHPMailer(); // defaults to using php "mail()"
  62.  
  63. $body             = $mail->getFile('contents.html');
  64. $body             = eregi_replace("[\]",'',$body);
  65.  
  66. $mail->From       = "[email protected]";
  67. $mail->FromName   = "First Last";
  68.  
  69. $mail->Subject    = "PHPMailer Test Subject via mail()";
  70.  
  71. $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  72.  
  73. $mail->MsgHTML($body);
  74.  
  75. $mail->AddAddress("[email protected]", "John Doe");
  76.  
  77. $mail->AddAttachment("images/phpmailer.gif");             // attachment Aqui debes adjuntar el fichero del cliente
  78.  
  79. if(!$mail->Send()) {
  80.   echo "Mailer Error: " . $mail->ErrorInfo;
  81. } else {
  82.   echo "Message sent!";
  83.  
  84.  
  85. ////////////mostramos mensaje de cortesia//////////////
  86.   $mensaje="Mensaje del formulario de contacto";
  87.   $mensaje.= "\nNombre: ". $_POST['nombre'];
  88.   $mensaje.= "\nApellidos: ". $_POST['apellidos'];
  89.   $mensaje.= "\nTelefono: ". $_POST['telefono'];
  90.   $mensaje.= "\nLocalidad: ". $_POST['localidad'];
  91.   $mensaje.= "\nC.P.: ". $_POST['cp'];
  92.   $mensaje.= "\nProvincia: ". $_POST['provincia'];
  93.   $mensaje.= "\nDirección: ". $_POST['direccion'];
  94.   $mensaje.= "\nMensaje: \n".$_POST['mensaje'];
  95.   $destino= "[email protected]";
  96.   $remitente = $_POST['email'];
  97.   $asunto = "Mensaje enviado por: ".$_POST['nombre'];
  98.   mail($destino,$asunto,$mensaje,"FROM: $remitente");
  99.   echo "Muchas gracias, datos enviados";
  100.  
  101. /////////////////////////////////////////////////////////////////////
  102.  
  103. }
  104. ?>
  105.  
  106. <?php
  107. }
  108. ?>

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.
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.