Ver Mensaje Individual
  #22 (permalink)  
Antiguo 24/04/2012, 11:42
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 responder

este es mi 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. //<![CDATA[
  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:'get',
  33.                        data: 'opciones='+arrayOpt,
  34.                        success: function(datos) {
  35.                            $('#respuesta').html(datos);
  36.                                                     }
  37.                    });
  38.                    
  39.                    return false;
  40.                });
  41.            });
  42.  
  43. //]]>
  44.  
  45.                    
  46.                  
  47.      
  48. </head>
  49. <form id="form1"  style="width: 50%;" name="form1">
  50. <fieldset><label for="nombre">Nombre</label> <input type="text" name="nombre" id="nombre" class="text ui-widget-content ui-corner-all" />
  51. <table border="0" id="users">
  52. <tr>
  53. <td width="244"><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" />
  54. Oscar Montes
  55. </label></td>
  56.  
  57. </tr>
  58. <tr>
  59. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Oscar Montes</label></td>
  60. </tr>
  61. <tr>
  62. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Diana Garcia</label></td>
  63. </tr>
  64. <tr>
  65. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Lucero Garcia</label></td>
  66. </tr>
  67. <tr>
  68.  
  69. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 5</label></td>
  70. </tr>
  71. <tr>
  72. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 6</label></td>
  73. </tr>
  74. <tr>
  75. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 7</label></td>
  76. </tr>
  77. <tr>
  78. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 8</label></td>
  79.  
  80. </tr>
  81. <tr>
  82. <td><label><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 9</label></td>
  83. </tr>
  84. <tr>
  85. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 10</td>
  86. </tr>
  87. <tr>
  88. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 11</td>
  89. </tr>
  90. <tr>
  91.  
  92. <td><input class="chk" type="checkbox" name="opcion[]" value="[email protected]" /> Destinatario 12</td>
  93. </tr>
  94. <tr>
  95. <td>&nbsp;</td>
  96. </tr>
  97. <tr>
  98. <td><label><input type='checkbox' id='chk_todos' value="checkbox" />
  99. </label> todos</td>
  100. </tr>
  101. <p>
  102.   <input name="contador" id="contador" type="text" value="ninguno" />
  103. </p>
  104. <p>
  105.   <label>
  106.   <input type="submit" name="Submit" value="Enviar" id="enviar"/>
  107.   </label>
  108. </p>
  109. </form>
  110. <div id="respuesta">
  111. </div>
  112.  
  113. </body>
  114. </html>

y el recibio.php

Código PHP:
Ver original
  1. nombre = $_POST["nombre"];
  2. echo $nombre;
  3. echo "<br>";
  4. $contador = $_POST["contador"];
  5. echo $contador;
  6. echo "<br>";
  7. $destinatarios = explode(',',$_POST['opcion']);
  8. echo implode(",", $destinatarios);
  9.  
  10. $servidor = 'localhost';
  11. $bd = 'insert';
  12. $usuario = 'postgres';
  13. $contrasenia = 'hoe798cs';
  14.    
  15. global $servidor, $bd, $usuario, $contrasenia;
  16. $db = new PDO('pgsql:host=' . $servidor . ';dbname=' . $bd, $usuario, $contrasenia);
  17.  
  18.  
  19. $consulta = $db->prepare("INSERT INTO ensayo (id,nombre,destinatarios)
  20.                                  VALUES (nextval('ensayo_id_seq'),'".$nombre."','$destinatarios')");
  21. $consulta->execute();
  22.  
  23.  
  24.  
  25. require_once('phpMailer/class.phpmailer.php');
  26. require_once("phpMailer/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
  27.  
  28. $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  29.  
  30. $mail->IsSMTP(); // telling the class to use SMTP
  31.  
  32.  
  33.   $mail->Host       = "smtp.live.com"; // SMTP server
  34.   $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  35.   $mail->SMTPAuth   = true;                  // enable SMTP authentication
  36.   //$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
  37.  
  38.   $mail->SMTPSecure = "tls";
  39.   $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
  40.   $mail->Username   = "[email protected]"; // SMTP account username
  41.   $mail->Password   = "oscarydiana";        // SMTP account password
  42.   //$mail->AddReplyTo('[email protected]', 'oscar');
  43.   foreach($_POST['opcion'] as $destinatarios) {
  44.  
  45.       $mail->addAddress($destinatarios);
  46.       //o bcc
  47.       $mail->addBcc($destinatarios);
  48. }
  49.   $mail->SetFrom('[email protected]', 'oscar');
  50.   //$mail->AddReplyTo('[email protected]', 'oscar');
  51.   $mail->Subject = 'Calendario Actividades Ingeominas';
  52.   $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  53.   $mail->MsgHTML("
  54. Estimado Usuario:<br />
  55. <br /><table width='36%' border='1' cellpadding='0' cellspacing='0' bordercolor='#E0ECFF' class='Estilo1'>
  56. <tr>
  57. <td colspan='2' bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='center'><strong>Actividad</strong></div></td>
  58. </tr>
  59. <tr align='center'>
  60. <td width='102' bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Evento</strong></div></td>
  61. <td width='289' bordercolor='#E0ECFF' bgcolor'#FFFFFF'>".$nombre."</td>
  62. </tr>
  63. <tr align='center'>
  64.  <td bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Hora Inicio</strong></div></td>
  65.  <td bordercolor='#E0ECFF' bgcolor'#FFFFFF'>".$nombre."</td>
  66.  </tr>
  67. <tr align='center'>
  68.  <td bordercolor='#E0ECFF' bgcolor='#FFFFFF'><div align='left'><strong>Hora Fin</strong></div></td>
  69.  <td bordercolor='#E0ECFF' bgcolor'#FFFFFF'>".$nombre."</td>
  70.  </tr>
  71. </table>");
  72. $mail->Send();

no se que estoy haciendo mal?

gracias por la ayuda.