breaststroke Posted August 25, 2012 Share Posted August 25, 2012 (edited) Hello, I have a problem involving Phpmailer and a While loop. Actually I have always had problems to sending emails this way. Now for instance I can send e-mails trough an IF (instead of While) and the following script works fine. But as soon as I change it into While it doesn't. Even the last part of the script (UPDATE) doesn't work (it worked upon IF). I am trying with just two e-mails to be sent and only the first one is sent.I would be so happy to solve this issue. While loop is really important when it comes to sending e-mails. This is my script: ...include('conexioninclude.php');mysql_set_charset('utf8');$registros=mysql_query("SELECT mail, name, password, codigo FROM alert WHERE status='on' AND language1='$language2' AND language2='$language1' AND way LIKE '%$way%' ORDER BY codigo",$conexion)ordie("Problems at selectt:".mysql_error());require("class.phpmailer.php");$mail = new PHPMailer();while($reg=mysql_fetch_array($registros)){$mailu=$reg['mail'];$namee=$reg['name'];$password=$reg['password'];$codigo=$reg['codigo'];$mail->IsSMTP();$mail->Port = 465;$mail->SMTPSecure = "ssl"; $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = true;$mail->Username = "xxxxx";$mail->Password = "xxxxxx"; // SMTP password$webmaster_email = "xxxxxx"; //Reply to this email ID$email="xxxxx"; // Recipients email ID$name="Admin"; // Recipient's name$mail->From = "xxxxxx";$mail->FromName = "Sharinglanguage.com";$mail->AddAddress($mailu,$namee);$mail->AddReplyTo(xxxxxx,"Webmaster");$mail->WordWrap = 50; // set word wrap$mail->SetLanguage("en","/php/language/");$mail->AddAttachment("/var/tmp/file.tar.gz");$mail->AddAttachment("/tmp/image.jpg", "phone.jpg");$mail->AddAttachment("image.jpg", "phone.jpg"); $mail->IsHTML(true); // send as HTML$mail->Subject = "xxxxxxxxx";$foto= "imagess/bonito.jpg";$mensaje='<font-color="#559999"><img src="'. $foto .'" width="600"><br /><br />Hello '.$namee.',<br /><br />xxxxxxxxxxxxxxxx .<br /><br />Sincerely yours</font>'; $mail->MsgHTML($mensaje);if(!$mail->Send()){print<<<HEREmessage wasn't sent;HERE;}else{$registros2=mysql_query("SELECT yep FROM vamos WHERE password='$password'",$conexion)ordie("Problems at selectt:".mysql_error());if($reg=mysql_fetch_array($registros)){$yep=$reg['yep']; // it's an Int type field (numbers)$saw=$yep+1;$registros3=mysql_query("UPDATE vamosSET yep='$saw'WHERE password='$password'",$conexion)ordie("Proble8uhims with selectttt:".mysql_error());}print<<<HEREsuccess!;HERE;}... Thank you very much in advance for any help. Regards Edited August 25, 2012 by breastsroke Link to comment Share on other sites More sharing options...
birbal Posted August 25, 2012 Share Posted August 25, 2012 what is happening when you run that code? any errors? Link to comment Share on other sites More sharing options...
breaststroke Posted August 25, 2012 Author Share Posted August 25, 2012 Hello! Thank you for replying.It doesn't return any errors. But only one e-mail is sent and the last query to the database doesn´t work either (there is no such UPDATE). Link to comment Share on other sites More sharing options...
birbal Posted August 25, 2012 Share Posted August 25, 2012 did you check how many rows are returning for this query? use mysqli_num_rows() http://php.net/mysqli_num_rows to check thatand check how many rows are updating using mysqli_affected_rows() http://php.net/mysqli_affected_rows it is possible that conditions is not matching so even if query is successfull it wont update or select as many rows you are expecting.if query fails it would show you errors. Link to comment Share on other sites More sharing options...
breaststroke Posted August 25, 2012 Author Share Posted August 25, 2012 (edited) I've found a solution, at least it has worked once. I had and have to do this: if($reg=mysql_fetch_array($registros2))since it belongs to $registros2. I hope it keeps working... birbal, thank you very much for replying, I hadn't seen your last message till after submitting mine. It seems I found the solution. I guess the While loop got stopped when it came across that wrong $registros.I'll check the links you provide. I didn't know about thoem and I am sure they'll come in handy.thank you very much again! p.s I have to do that when I do a query through $registros2, before the Update Edited August 25, 2012 by breastsroke Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now