Jump to content
Sign in to follow this  
breaststroke

Sending e-mails with PhpMailer through a WHILE loop (it works with IF)

Recommended Posts

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 by breastsroke

Share this post


Link to post
Share on other sites

what is happening when you run that code? any errors?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by breastsroke

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...