check if email account is available?

nowayin

Registered
Aug 3, 2013
3
0
1
cPanel Access Level
Website Owner
I'm using the XML-API class and I don't see a function to check if an email is available or not.
I want to check my cPanel to see if that email is taken already, if yes, return true, then if not return false.

I tried using this function :
PHP:
$result = $xmlapi->api2_query($account, "Email", "listpops");
But it just lists all the email that is on the cPanel account.
Is there an $arg I can use to check if an email already exist?

Maybe something like
$result = $xmlapi->api2_query($account, "Email", "listpops", array($email));
If the email exist
return true
else
return false

I've been searching and looking but the functions I found was for WHM.
 

nowayin

Registered
Aug 3, 2013
3
0
1
cPanel Access Level
Website Owner
Never mind I found the solution to my problem.
What I did was use the API2 and use the function "editquota" to edit the quota of a user. If the edit is successful that means the user already exist in the database, if edit is unsuccessful then the user is not there.

If anyone happens to stumble upon this tread and is looking for the same thing, here is the code :

PHP:
$result = $xmlapi->api2_query($account, "Email", "editquota", array( 'domain' => "domain.com", 'email' => "username", 'quota' => "1024") );
Then, to check if the username is taken or not :

PHP:
if (strpos($result, 'not') == true ) {
	echo 'available';
}
else{
	echo 'taken';
}
Make sure you set
PHP:
$xmlapi->set_output('xml');
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,201
363
Hello :)

I am happy to hear you were able to resolve the issue. Thank you for sharing the solution.