I have this code:
include "xmlapi.php";
$pass = 'testing1234';
$auser = 'testing';
$server = "0.0.0.0";
$port = 2087;
$remote_api = new xmlapi($server);
$remote_api->password_auth($auser, $pass);
$remote_api->set_port($port);
$remote_api->set_output('json');
$json_list = $remote_api->xmlapi_query('listaccts', array( 'api.version'=> 1));
$list = json_decode($json_list, true);
if ( ! is_array($list)
|| ! array_key_exists('data', $list)
|| ! is_array($list['data'])
|| ! array_key_exists('acct', $list['data'])
) {
die("Invalid response!");
}
$email_list = array();
foreach ($list['data']['acct'] as $acct) {
$username = $acct['user'];
$json_emails = $remote_api->api2_query($username, 'Email', 'listpopswithdisk', array());
$acct_emails = json_decode($json_emails, true);
if ( is_array($acct_emails)
&& array_key_exists('cpanelresult', $acct_emails)
&& is_array($acct_emails['cpanelresult'])
&& array_key_exists('data', $acct_emails['cpanelresult'])
&& is_array($acct_emails['cpanelresult']['data'])
) {
foreach ($acct_emails['cpanelresult']['data'] as $an_email) {
array_push(
$email_list,
array(
'cpanel_account' => $username,
'domain' => $an_email['domain'],
'email' => $an_email['user'],
'full_email' => $an_email['email'],
'diskused' => $an_email['diskused'],
)
);
echo $an_email['email'] . ' - ';
echo $an_email['diskused'] . ' - ';
echo $an_email['user'] . '<br>';
}
}
}
I used this code to connect to my cpanel and list all the email on the server. At first I just use var_dump to see if it works. And tried to use foreach loop but not success. How can I do a loop to echo all the data, so I can put the data in a table or something like that.
Please help me with this, thank you.