- $contact = format_email_recipient($sql_arr['email'], $sql_arr['name']);
- // when we've got more than one book, we need to skip duplicates
- if ($books_num == 1 || !in_array($contact, $contacts)) {
- $contacts[] = $contact;
- if (count($contacts) >= $MAXNUM)
- break 2;
+ // Contact can have more than one e-mail address
+ $email_arr = (array)$abook->get_col_values('email', $sql_arr, true);
+ $email_cnt = count($email_arr);
+ foreach ($email_arr as $email) {
+ if (empty($email))
+ continue;
+ $contact = format_email_recipient($email, $sql_arr['name']);
+ // skip entries that don't match
+ if ($email_cnt > 1 && stripos($contact, $search) === false) {
+ continue;
+ }
+ // when we've got more than one book, we need to skip duplicates
+ if ($books_num == 1 || !in_array($contact, $contacts)) {
+ $contacts[] = $contact;
+ if (count($contacts) >= $MAXNUM)
+ break 2;
+ }