Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending e-mails through a WHILE loop with Phpmailer fails (only one is sent)

Status
Not open for further replies.

breaststroke

Programmer
Apr 10, 2011
39
ES
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:

PHP:
...
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)or
die("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<<<HERE
message wasn't sent;
HERE;
}
else
{
$registros2=mysql_query("SELECT yep FROM vamos WHERE password='$password'",$conexion)or
die("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 vamos
SET yep='$saw'
WHERE password='$password'",$conexion)or
die("Proble8uhims with selectttt:".mysql_error());
}
print<<<HERE
success!;
HERE;
}
...

Thank you very much in advance for any help.

Regards!


enjoy practicing languages at:
 
I've found a solution, at least it has worked once. I had and have to do the following, when I do a query with Sregistros2, before the Update:


if($reg=mysql_fetch_array($registros2))
since it belongs to $registros2. I hope it keeps working...




enjoy practicing languages at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top