Ver Mensaje Individual
  #25 (permalink)  
Antiguo 28/02/2012, 19:43
manugiralda
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Problema con checkbox, solo recoge un dato

Cita:
Iniciado por manugiralda Ver Mensaje
$A = 1;
foreach ($_POST['select'.$A] as $email){

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);


$mail = new PHPMailer();

$mail->IsHTML(true);

$mail->CharSet = 'UTF-8';

$mail->IsSMTP();

$mail->Host = "smtp.gmail.com";

$mail->From = "[email protected]";

$mail->FromName = "Car freight INC.";

$mail->Subject = "Do-Not-Replay Car Freight";

$mail->MsgHTML($body);


$mail->AddAddress($email);

$mail->AddBCC("[email protected]"); // Copia oculta

$mail->SMTPAuth = true;

$mail->Username = "[email protected]";

$mail->Password = "contraseña";

$A++;
}
Vale creo que el fallo se puede originar por el bucle foreach precisamente. Es porque si no seleccionas todos los checlbox en orden, el bucle se corta. A ver si me explico. Si seleccionas el Check2 y no el check1, el primer check no esta definido y entonces se cortaria y no da lugar a pasar al siguiente check.

Prueba cambiando el bucle foreach por el for que te puse yo y condicionandlo el envio del mensaje a que haya algo en la variable $_POST['select'.$A].

Prueba a dejarlo asi.

Código PHP:

//Calcula la cantidad de checlbox que tienes para que el bucle se suceda todas esas veces


$numcheckbox 20//esto es suponiendo qye tubieses 20 checbox.


for ($A=1;$A<=$numcheckbox;$A++){

if(
$_POST['select'.$A]!=""){

$email $_POST['select'.$A];

$body file_get_contents('contents.html');
$body eregi_replace("[\]",'',$body);


$mail = new PHPMailer();

$mail->IsHTML(true);

$mail->CharSet 'UTF-8';

$mail->IsSMTP();

$mail->Host "smtp.gmail.com";

$mail->From "[email protected]";

$mail->FromName "Car freight INC.";

$mail->Subject "Do-Not-Replay Car Freight";

$mail->MsgHTML($body);


$mail->AddAddress($email);

$mail->AddBCC("[email protected]"); // Copia oculta

$mail->SMTPAuth true;

$mail->Username "[email protected]";

$mail->Password "contraseña";

}


Asi deberia funcinarte seguro.