I have the following bit of code which works for some records in active director but returns "Notice: Undefined index: mail in C:\xampp\htdocs\utils.php on line 57".
Line 57 is "$email = ($data[$i]["mail"][0]);"
Could this be a problem with the code or is there something in AD that is preventing the access of the "mail" property. It only returns the error on some records not all. For most records, I get the correct return back.
Thanks in advance.
$attributes = array("samaccountname", "sn", "givenname", "mail");
$search_filter = "(&(givenname=$firstName)(sn=$lastName))";
$search = ldap_search($ds, $dn, $search_filter, $attributes, 0, 0);
$data = ldap_get_entries($ds, $search);
$rows = array();
for ($i=0; $i<$data["count"]; $i++) {
if (isset($data[$i]["sn"][0], $data[$i]["givenname"][0])) {
$email = ($data[$i]["mail"][0]);
echo $email;
array_push($rows,$email);
}
}
echo json_encode($rows);