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 = "dsmjelcar@gmail.com";
$wiad->Password = "jelcar1234";

$wiad->From = "dsmjelcar@gmail.com"; //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
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.