How to extract domain name from an e-mail address string

If, for any reason, you need to extract the domain from an e-mail address (or from multiple e-mail address that are in a database) then you can use this function:

function getDomainFromEmail($email)
    // Get the data after the @ sign
    $domain = substr(strrchr($email, "@"), 1);

    return $domain;

// Example

$email = '[email protected]';

$domain = getDomainFromEmail($email);

echo $domain; //

Comment via Facebook



  1. Gokul Shinde says

    This function returns all domain name after @ sign. I need only domain name like “yahoo” or “gmail” or “tcs” or “ibm” etc. for emails like “[email protected]”.

Leave a Reply

Your email address will not be published. Required fields are marked *