Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if user has no mail address #3

Closed
sadden3194 opened this issue Jan 14, 2021 · 2 comments
Closed

Check if user has no mail address #3

sadden3194 opened this issue Jan 14, 2021 · 2 comments

Comments

@sadden3194
Copy link

sadden3194 commented Jan 14, 2021

Good morning,

me again (shame on me).

I check with this code if a contact has a specific mail address:

foreach ($contacts as $contact) {
   $vcard = $abook->getCard($contact->getUri());
   
   if ($vcard["vcard"]->EMAIL->getvalue() == "mail@domain.com") {
      echo "Mail exist!";
      exit();
   } else {
      echo "No";
}

Problem:
If a contact has no mail address I get this error:

Notice: Undefined index: EMAIL; Fatal error: Uncaught Error: Call to a member function getvalue() on null

How can I handle this?

@mstilkerich
Copy link
Owner

A VCard can have no EMAIL property, but it may also have multiple EMAIL properties. Your code should be able to deal with these situations, it currently assumes that each card as one EMAIL property (only).

Something like:

if (isset($vcard->EMAIL)) {
    foreach($vcard->EMAIL as $email) {
        echo "Email: $email\n";
    }
}

@sadden3194
Copy link
Author

Thank you very much AGAIN 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants