Ver Mensaje Individual
  #42 (permalink)  
Antiguo 30/04/2012, 23:05
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

Hola amigos ya solucione mi problema , quiero agraderle a todos los que postearon pero principalmente a Nemutagk, gildus sin ellos no hubiese podido

gracias

este es el codigo funcional


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.                        
  12.                             if ($(this).attr('checked') != 'checked') {
  13.                                 $(this).attr('checked','checked');
  14.                             }else {
  15.                                 $(this).removeAttr('checked');
  16.                             }
  17.                         }
  18.                     });
  19.                 });
  20.                
  21.                 $('#enviar').on('click',function() {
  22.                     var arrayOpt = new Array;
  23.               $('input[type=checkbox]').each(function() {
  24.                         if ($(this).attr('name') == 'opcion[]') {
  25.                             if ($(this).attr('checked') == 'checked') {
  26.                                 arrayOpt.push($(this).val());
  27.                                
  28.                             }
  29.                         }
  30.                     });
  31.                        var evento =  $("#evento").val();
  32.                        var fechainicio =  $("#fechainicio").val();
  33.                        var fechafinal =  $("#fechafinal").val();
  34.                        var prueba = $("#prueba").val();
  35.                       // alert(nombre);
  36.                        
  37.                     $.ajax({
  38.                         url:'recibio.php',
  39.                         type:'post',
  40.                         data:'opciones='+arrayOpt+'&evento='+evento+'&fechainicio='+fechainicio+'&fechafinal='+fechafinal+'&prueba='+prueba,
  41.                         success: function(datos) {
  42.                         $('#respuesta').html(datos);
  43.                                             alert(evento+" "+arrayOpt+" "+fechainicio+" "+fechafinal);}
  44.                     });
  45.                                        
  46.                     return false;
  47.                 });
  48.             });
  49.  
  50.  
  51.                    
  52.                  
  53.      
  54. </head>
  55. <form style="width: 50%;">
  56. <fieldset><label for="nombre">Nombre</label> <input type="text" name="evento" id="evento" class="text ui-widget-content ui-corner-all"/>
  57. <br>
  58. Fecha Inicio
  59. <input type="text" name="fechainicio" id="fechainicio" class="text ui-widget-content ui-corner-all" value="2012-04-06 00:00:00-05"/>
  60. <br>
  61. Fecha Final
  62. <input type="text" name="fechafinal" id="fechafinal" class="text ui-widget-content ui-corner-all" value="2012-04-06 00:00:00-05"/>
  63. <br>
  64. <table border="0" id="users">
  65. <tr>
  66. <td width="244"><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" />
  67. Oscar Montes
  68. </label></td>
  69.  
  70. </tr>
  71. <tr>
  72. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Oscar Montes</label></td>
  73. </tr>
  74. <tr>
  75. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Diana Garcia</label></td>
  76. </tr>
  77. <tr>
  78. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Lucero Garcia</label></td>
  79. </tr>
  80. <tr>
  81.  
  82. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 5</label></td>
  83. </tr>
  84. <tr>
  85. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 6</label></td>
  86. </tr>
  87. <tr>
  88. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 7</label></td>
  89. </tr>
  90. <tr>
  91. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 8</label></td>
  92.  
  93. </tr>
  94. <tr>
  95. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 9</label></td>
  96. </tr>
  97. <tr>
  98. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 10</td>
  99. </tr>
  100. <tr>
  101. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 11</td>
  102. </tr>
  103. <tr>
  104.  
  105. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 12</td>
  106. </tr>
  107. <tr>
  108. <td>&nbsp;</td>
  109. </tr>
  110. <tr>
  111. <td><label><input type='checkbox' id='chk_todos' value="checkbox" />
  112. </label> todos</td>
  113. </tr>
  114. <p>
  115.    <label>
  116.    <input name="prueba" type="text" id="prueba" value="TRUE">
  117.    </label>
  118. </p>
  119. <p>
  120.   <label></label>
  121. </p>
  122. <p>
  123.   <label>
  124.   <input type="submit" name="Submit" value="Enviar" id="enviar" />
  125.   </label>
  126. </p>
  127. <div id="respuesta"><b></b></div>
  128. </form>
  129.  
  130. </body>
  131. </html


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