Jump to content

PHPMailer looping AddAddress


tomaszko

Recommended Posts

Hello ,

i've got a little problem. I'm checking list of recipents by checkboxes. Then it should send mail to everyony of selected recipents. But it only works with ONE recipent. I know that part:

$wiad->AddAddress ($mail)

needs to be looped, but i can't manage to do that :(

 

<?php include ('conf.php'); ?>
<?php
if(isset($_GET["sortuj"]))
$sortuj = $_GET["sortuj"];
else
$sortuj = "id_klient";

// wygeneruj tabelê ze wszystkimi produktami

$zapytanie = "SELECT * FROM klient ORDER BY $sortuj "; 
//$zapytanie = "SELECT * FROM produkty ORDER BY nazwa" ; 
$wynik = mysql_query($zapytanie) or die ('B³±d: '. mysql_error());

$zapytanie2 = "SELECT * FROM szablon"; 
//$zapytanie = "SELECT * FROM produkty ORDER BY nazwa" ; 
$szablon = mysql_query($zapytanie2) or die ('Błąd: '. mysql_error());



?>
<table method='get'>
<tr><th></th><th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=imie">Imię</a>
  </th><th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=nazwisko">Nazwisko</a>
  </th><th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=telefon">Telefon</a></th><th><a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=mail">Mail</a> </th>
<th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=miasto">Miasto</a></th><th><a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=ulica">Ulica</a> </th>
<th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=kodpocztowy">Kod Pocztowy</a></th><th><a href="#" id="expander">Zwiń</a></th></tr>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php
while ($rekord = mysql_fetch_assoc($wynik)) {
?>
<tr>
		<td><input type="checkbox" name="id[]" value="<?php echo $rekord['id_klient']; ?>" /></td>
		<td><?php echo $rekord['imie'];?></td>
		<td><?php echo $rekord['nazwisko'];?></td>
		<td><?php echo $rekord['telefon']; ?></td>
		<td><?php echo $rekord['mail']?></td>
		<td><?php echo $rekord['miasto'];?></td>
		<td><?php echo $rekord['ulica']; ?></td>
		<td><?php echo $rekord['kodpocztowy']; ?></td>

</td>
</tr>

<?php
}
?></table><br>
<table method='get'>
<tr> <th></th>
<th>
Tytuł</th><th>Treść</th></tr>

<?php
while ($rekord = mysql_fetch_assoc($szablon)) {
?>
<tr>
		<td><input type="radio" name="cont[]" value="<?php echo $rekord['id_szablon']; ?>"/></td>
		<td><?php echo $rekord['tytul'];?></td>
		<td><?php echo $rekord['tresc'];?></td>
</tr>
<?php
}
?>
</table>

<?php
if(isset($_POST['klik'])) {
if(isset($_POST['id'])){

	$mail='';
	$nazwisko='';
	$imie='';
foreach($_POST['id'] as $idi){
$sql="SELECT imie,nazwisko,mail FROM klient WHERE id_klient=".$idi;
$res=mysql_query($sql);
$dane_klienta=mysql_fetch_array($res);

$imie=$imie.''.$dane_klienta[0];
$nazwisko=$nazwisko.''.$dane_klienta[1];
$mail=$mail.''.$dane_klienta[2];
}
if(isset($_POST['cont'])){

	$tytul='';
	$tresc='';
foreach($_POST['cont'] as $conti){
$zap="SELECT tytul,tresc FROM szablon WHERE id_szablon=".$conti;
$w=mysql_query($zap);
$cont_szablon=mysql_fetch_array($w);

$tytul=$tytul.''.$cont_szablon[0];
$tresc=$tresc.''.$cont_szablon[1];
}

require_once($_SERVER['DOCUMENT_ROOT'].'/lib/phpmailer/class.phpmailer.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/phpmailer/class.smtp.php');
  


$wiad = new PHPMailer();  // Instantiate your new class
$wiad->IsSMTP();          // set mailer to use SMTP
$wiad->SMTPAuth = true;   // turn on SMTP authentication
$wiad->Host = "smtp.gmail.com"; // specify main and backup server
$wiad->SMTPSecure= 'ssl'; //  Used instead of TLS when only POP mail is selected
$wiad->Port = 465;        //  Used instead of 587 when only POP mail is selected

$wiad->Username = "xxx";
$wiad->Password = "xxx";

$wiad->From = "xxx"; //Aparently must be the same as the UserName
$wiad->FromName = "xxx";

$wiad->CharSet = "UTF-8";

$wiad->AddAddress ($mail);

$wiad->Body = ($tytul);
$wiad->AltBody = "Wiadomosc txt";
$wiad->Subject = ($tresc);

if(!$wiad->Send())
{
  echo "There was an error sending the message:" . $wiad->ErrorInfo;
  	
  exit;
}
else {	
$wiad->clearAddresses();
  	echo "Wysłano";
  	}
  	
}else{echo 'Wybierz odbiorców/szablon.';
  	
}}}
?>

<input type="submit" name="klik" value="Wyslij" onClick='fireMyPopup()'>
<br/></form>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.