Ver Mensaje Individual
  #7 (permalink)  
Antiguo 03/03/2012, 14:27
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 10 meses
Puntos: 6
Respuesta: envio de correo mediante phpMailer de consulta

amigos ya logro enviar el correo , pero tengo un problema envia 2 veces el correo y solo lo necesito una vez

Código PHP:
Ver original
  1. $correo = $_POST['email'];
  2. //$id = $_POST['id'];
  3. //echo "<br>";
  4. //echo $_REQUEST['captcha_code'];
  5.  
  6.  
  7.   require_once('phpMailer/class.phpmailer.php');
  8.   require_once("phpMailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  9.  
  10.   $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  11.   $mail->IsSMTP(); // telling the class to use SMTP
  12.   $mail->Host       = 'smtp.live.com'; // SMTP server
  13.   $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  14.   $mail->SMTPAuth   = true;                  // enable SMTP authentication
  15.   $mail->Host       = 'smtp.live.com'; // sets the SMTP server
  16.   $mail->SMTPSecure = 'tls';
  17.   $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
  18.   $mail->Username   = '[email protected]'; // SMTP account username
  19.   $mail->Password   = 'oscarydiana';        // SMTP account password
  20.   $mail->AddAddress($_POST['email']);
  21.   $mail->SetFrom($_POST['email']);
  22.   $mail->Subject = 'Recuperar Contraseña';
  23.   $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  24.  
  25.   $mensaje="Estimado Usuario:<br />
  26. <br /><table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#E0ECFF' class='Estilo1'>
  27. <tr>
  28. <td width='113' height='22' valign='middle' background'grid3-hrow.gif' class='borexterior' id='oferta_1'><div align='center'><strong>Usuario</strong></div></td>
  29. <td width='104' valign='middle' background='grid3-hrow.gif' class='borexterior' id='oferta_2'><div align='center'><strong>Contraseña</strong></div></td>
  30. </tr>";
  31.  
  32.  $servidor = 'localhost';
  33. $bd = 'calendario';
  34. $usuario = 'postgres';
  35. $contrasenia = 'hoe798cs';
  36.    
  37. global $servidor, $bd, $usuario, $contrasenia;
  38. $db = new PDO('pgsql:host=' . $servidor . ';dbname=' . $bd, $usuario, $contrasenia);
  39.  
  40. $consulta = $db->prepare("SELECT * FROM usuario  WHERE correo = '".$correo."'");
  41. $consulta->execute();
  42.  
  43.   while($fila = $consulta->fetch(PDO::FETCH_ASSOC))
  44.     {
  45.  //$cuenta=$fila['cuenta'];
  46.  //$contasena=$fila['contrasena'];
  47.  $mensaje.="<tr align='center'>
  48. <td bordercolor='#E0ECFF' bgcolor='#FFFFFF'>".$fila['cuenta']."</td>
  49. <td bordercolor='#E0ECFF' bgcolor'#FFFFFF'>".$fila['contrasena']."</td>
  50. </tr>
  51. </table>";
  52. }
  53.  
  54.    
  55.   $mail->Body = $mensaje;
  56.   $mail->Send();
  57.   if(!$mail->Send()){
  58.    //echo "No se pudo enviar el Mensaje.";
  59.    echo '<script languaje="Javascript">location.href="views/frm_sucess_correo_no.php"</script>';
  60.    
  61. }else{
  62.    //echo "Mensaje enviado";
  63.    echo '<script languaje="Javascript">location.href="views/frm_sucess_correo.php"</script>';
  64. }