Jump to content

Sending to group


tomaszko

Recommended Posts

Hi,

todays problem. I've database of clients, some of them are in groups. Sending msg to choosen clients works perfectly, but to specified group no. Oh and one more thing. For now it only sends to FIRST client in GROUP. Here is tables:

client:

id_client
group_id
name
surname
mail

group:

id_group
name

 

and PHP code:

 <table method='get'>
<tr><th></th><th>
<a href="<?php echo $_SERVER['PHP_SELF'];?>?sortuj=nazwa">Nazwa</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_grupa']; ?>" /></td>
		<td><?php echo $rekord['nazwa'];?></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='';

$allEmails = array(); // This will hold ALL email addresses you want to send to 
foreach($_POST['id'] as $idi){
$sql="SELECT imie,nazwisko,mail FROM klient, grupa WHERE klient.grupa_id = ".$idi;
//$sql="SELECT imie,nazwisko,mail FROM klient, grupa 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=$dane_klienta[2];

$allEmails[] = $mail; // add this address 
}
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 = "[email protected]";
$wiad->Password = "jelcar1234";

$wiad->From = "[email protected]"; //Aparently must be the same as the UserName
$wiad->FromName = "JelCar";

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

foreach ($allEmails as $mail) { 
$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 {	   

//	$zapytanie = "INSERT INTO klient_mail,mail (id_klient, id_mail), (tytul, tresc) VALUES ('$idi','$conti'), ('$tytul', '$tresc')";
//	$wstaw = mysql_query($zapytanie);
$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
https://forums.phpfreaks.com/topic/228184-sending-to-group/
Share on other sites

not much use with php arrays myself, but this looks suspect :

$allEmails[] = $mail; // add this address 

 

I would expect it should look like :

$allEmails[$idi] = $mail; // add this address

or

$allEmails[] => $mail; // add this address 

But you'll need to look into it some more, as I said, I'm not too hot on php arrays.

Link to comment
https://forums.phpfreaks.com/topic/228184-sending-to-group/#findComment-1176716
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.