Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach($_POST['Trainee_Name'] as $traineename) //Field Name in the dynamic table
- {
- $username="***";
- $password="***";
- $lc = ldap_connect("***") or
- die("Couldn't connect to AD!");
- ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_bind($lc,$username,$password);
- $base = "OU=**,DC=**,DC=**";
- $filt = "(&(&(&(objectCategory=person)(objectClass=user)(name=$traineename*))))";
- $sr = @ldap_search($lc, $base, $filt);
- $info = ldap_get_entries($lc, $sr);
- for ($j = 0; $j < $info["count"]; $j++)
- {
- echo $address[]=$info[$j]["mail"][0]."<br/>" ; //echo's the email ID
- }
- if ($j == 0)
- {
- echo "No matches found!";
- }
- ldap_close($lc);
- }
- foreach($address as $recipientsaddress)
- {
- $email_body = $email_body ."Test";
- require_once("class.phpmailer.php");
- $mail = new PHPMailer();
- $mail->IsSMTP();
- $mail->SMTPAuth = true;
- $mail->Host = "***";
- $mail->SetFrom('***');
- $mail->Subject = "Test";
- $mail->MsgHTML($email_body);
- $mail->AddAddress($recipientsaddress);
- if($mail->Send()) {
- echo "Success";
- }
- else echo "ERROR";
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement