Advertisement
Guest User

Untitled

a guest
May 13th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. foreach($_POST['Trainee_Name'] as $traineename) //Field Name in the dynamic table
  2. {
  3. $username="***";
  4. $password="***";
  5. $lc = ldap_connect("***") or
  6. die("Couldn't connect to AD!");
  7. ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, 3);
  8. ldap_bind($lc,$username,$password);
  9. $base = "OU=**,DC=**,DC=**";
  10. $filt = "(&(&(&(objectCategory=person)(objectClass=user)(name=$traineename*))))";
  11. $sr = @ldap_search($lc, $base, $filt);
  12. $info = ldap_get_entries($lc, $sr);
  13. for ($j = 0; $j < $info["count"]; $j++)
  14. {
  15. echo $address[]=$info[$j]["mail"][0]."<br/>" ; //echo's the email ID
  16. }
  17. if ($j == 0)
  18. {
  19. echo "No matches found!";
  20. }
  21. ldap_close($lc);
  22. }
  23.  
  24. foreach($address as $recipientsaddress)
  25. {
  26. $email_body = $email_body ."Test";
  27.  
  28. require_once("class.phpmailer.php");
  29. $mail = new PHPMailer();
  30. $mail->IsSMTP();
  31. $mail->SMTPAuth = true;
  32. $mail->Host = "***";
  33. $mail->SetFrom('***');
  34. $mail->Subject = "Test";
  35. $mail->MsgHTML($email_body);
  36. $mail->AddAddress($recipientsaddress);
  37.  
  38. if($mail->Send()) {
  39. echo "Success";
  40. }
  41. else echo "ERROR";
  42.  
  43. exit;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement