Ver Mensaje Individual
  #27 (permalink)  
Antiguo 24/04/2012, 23:00
Montes28
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 7 meses
Puntos: 6
Respuesta: Envio de correo a varios destinatarios con phpMailer

Nemutagk gracias por la disposición de ayuda

no estoy recibiendo nada ya intente por get y por post

este es todo mi codigo codigo

Código HTML:
Ver original
  1. <title>titulo</title>
  2. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  3. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
  4.  
  5. <script type='text/javascript'>
  6.  
  7. $(document).on('ready',function() {
  8.                 $('#chk_todos').on('click', function() {
  9.                     $('input[type=checkbox]').each(function() {
  10.                         if ($(this).attr('name') == 'opcion[]') {
  11.                             if ($(this).attr('checked') != 'checked') {
  12.                                 $(this).attr('checked','checked');
  13.                             }else {
  14.                                 $(this).removeAttr('checked');
  15.                             }
  16.                         }
  17.                     });
  18.                 });
  19.                
  20.                 $('#enviar').on('click',function() {
  21.                     var arrayOpt = new Array;
  22.                     $('input[type=checkbox]').each(function() {
  23.                         if ($(this).attr('name') == 'opcion[]') {
  24.                             if ($(this).attr('checked') == 'checked') {
  25.                                 arrayOpt.push($(this).val());
  26.                             }
  27.                         }
  28.                     });
  29.                    
  30.                     $.ajax({
  31.                         url:'recibio.php',
  32.                         type:'post',
  33.                         data: 'opciones='+arrayOpt,
  34.                         success: function(datos) {
  35.                                             }
  36.                     });
  37.                                        
  38.                     return false;
  39.                 });
  40.             });
  41.  
  42.  
  43.                    
  44.                  
  45.      
  46. </head>
  47. <form id="form1"  style="width: 50%;">
  48. <fieldset><label for="nombre">Nombre</label> <input type="text" name="nombre" id="nombre" class="text ui-widget-content ui-corner-all" />
  49. <table border="0" id="users">
  50. <tr>
  51. <td width="244"><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" />
  52. Oscar Montes
  53. </label></td>
  54.  
  55. </tr>
  56. <tr>
  57. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Oscar Montes</label></td>
  58. </tr>
  59. <tr>
  60. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Diana Garcia</label></td>
  61. </tr>
  62. <tr>
  63. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Lucero Garcia</label></td>
  64. </tr>
  65. <tr>
  66.  
  67. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 5</label></td>
  68. </tr>
  69. <tr>
  70. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 6</label></td>
  71. </tr>
  72. <tr>
  73. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 7</label></td>
  74. </tr>
  75. <tr>
  76. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 8</label></td>
  77.  
  78. </tr>
  79. <tr>
  80. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 9</label></td>
  81. </tr>
  82. <tr>
  83. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 10</td>
  84. </tr>
  85. <tr>
  86. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 11</td>
  87. </tr>
  88. <tr>
  89.  
  90. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 12</td>
  91. </tr>
  92. <tr>
  93. <td>&nbsp;</td>
  94. </tr>
  95. <tr>
  96. <td><label><input type='checkbox' id='chk_todos' value="checkbox" />
  97. </label> todos</td>
  98. </tr>
  99. <p>
  100.   <input name="contador" id="contador" type="text" value="ninguno" />
  101. </p>
  102. <p>
  103.   <label>
  104.   <input type="submit" name="Submit" value="Enviar" id="enviar" />
  105.   </label>
  106. </p>
  107. </form>
  108. </body>
  109. </html>


y en recibio.php

Código PHP:
Ver original
  1. $destinatarios = explode(',',$_POST['opciones']);
  2. $servidor = 'localhost';
  3. $bd = 'insert';
  4. $usuario = 'postgres';
  5. $contrasenia = 'hoe798cs';
  6.    
  7. global $servidor, $bd, $usuario, $contrasenia;
  8. $db = new PDO('pgsql:host=' . $servidor . ';dbname=' . $bd, $usuario, $contrasenia);
  9.  
  10.  
  11. $consulta = $db->prepare("INSERT INTO ensayo (id,nombre,destinatarios)
  12.                                  VALUES (nextval('ensayo_id_seq'),'".Montes."','$destinatarios')");
  13. $consulta->execute();
  14.  
  15. require_once('phpMailer/class.phpmailer.php');
  16. require_once("phpMailer/class.smtp.php");
  17.  
  18. $mail = new PHPMailer(true);
  19.  
  20. $mail->IsSMTP();
  21.  
  22.  
  23.   $mail->Host       = "smtp.live.com";
  24.   $mail->SMTPDebug  = 2;                    
  25.   $mail->SMTPAuth   = true;                  
  26.  
  27.  
  28.   $mail->SMTPSecure = "tls";
  29.   $mail->Port       = 25;                    
  30.   $mail->Username   = "[email protected]";
  31.   $mail->Password   = "***";        
  32.  
  33.   $mail->AddReplyTo('[email protected]', 'oscar');
  34.   foreach($_POST['opciones'] as $destinatarios) {
  35.  
  36.       $mail->addAddress($destinatarios);
  37.  
  38.       $mail->addBcc($destinatarios);
  39. }
  40.   $mail->SetFrom('[email protected]', 'oscar');
  41.  
  42.   $mail->Subject = 'prueba';
  43.   $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  44.   $mail->MsgHTML("
  45. Estimado Usuario:<br />
  46. <br /><table width='36%' border='1' cellpadding='0' cellspacing='0' bordercolor='#E0ECFF' class='Estilo1'>
  47. <tr>
  48. <td colspan='2' bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='center'><strong>Actividad</strong></div></td>
  49. </tr>
  50. <tr align='center'>
  51. <td width='102' bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Evento</strong></div></td>
  52. <td width='289' bordercolor='#E0ECFF' bgcolor'#FFFFFF'>""</td>
  53. </tr>
  54. <tr align='center'>
  55.  <td bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Hora Inicio</strong></div></td>
  56.  <td bordercolor='#E0ECFF' bgcolor'#FFFFFF'>""</td>
  57.  </tr>
  58. <tr align='center'>
  59.  <td bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Hora Fin</strong></div></td>
  60.  <td bordercolor='#E0ECFF' bgcolor'#FFFFFF'>""</td>
  61.  </tr>
  62. </table>");
  63. $mail->Send();