0

我使用 XML API 到 cpanel 从 PHP 页面创建电子邮件帐户。

我在创建代码以查看电子邮件帐户是否设置成功时遇到问题。

我的 PHP 文件如下所示:

<?
if(isset($_POST[token])) {
include("xmlapi.php");        //XMLAPI cpanel client class

$email = $_POST['email'];
$password = $_POST['password'];

$ip = "IP";            // should be server IP address or 127.0.0.1 if local server
$account = "USERNAME";        // cpanel user account name
$passwd ="PASSWORD";          // cpanel user password
$port =2083;                  // cpanel secure authentication port unsecure port# 2082
$email_domain ="DOMAIN";
$email_user ="$email";
$email_pass ="$password";
$email_quota = 500;             // 0 is no quota, or set a number in mb

$xmlapi = new xmlapi($ip);
$xmlapi->set_port($port);     //set port number.
$xmlapi->password_auth($account, $passwd);
$xmlapi->set_debug(1);        //output to error file  set to 1 to see error_log.

$call = array(domain=>$email_domain, email=>$email_user, password=>$email_pass, quota=>$email_quota);

$result = $xmlapi->api2_query($account, "Email", "addpop", $call );

?>

如果电子邮件帐户创建成功,我会收到以下回复:

SimpleXMLElement Object ( [apiversion] => 2 [data] => SimpleXMLElement Object ( [reason] => SimpleXMLElement Object ( ) [result] => 1 ) [event] => SimpleXMLElement Object ( [result] => 1 ) [func ] => addpop [模块] => 电子邮件)

如果不是我得到这个:

SimpleXMLElement Object ( [apiversion] => 2 [data] => SimpleXMLElement Object ( [reason] => 您输入的密码强度等级为“23”。您不能使用它,因为它太弱了... [结果] => 0 ) [error] => 您输入的密码强度等级为“23”。您不能使用它,因为它太弱了... [event] => SimpleXMLElement Object ( [result] => 1 ) [func] => addpop [module] => 电子邮件)

我尝试使用此代码但没有用:

if ($result->result->status) {
print "Creation of account worked successfully!";
}
else {
print "Creation Failed:" $result->result->statusmsg;
}

我将不胜感激帮助和快速响应,谢谢。

4

1 回答 1

0

您可以使用如下响应:-

-- 生成一个新的电子邮件地址

   $api2args = array(
        'domain'          => $domain, 
        'email'           => $email_to_create, 
        'password'        => $password,
        'quota'           => '2048',                                
    );
    $result = $xmlapi->api2_query($username, 'Email', 'addpop',$api2args);

     if(isset($result->error) && $result->error!=""){               
          // error handling will be here                
      }
      else{
          // success message can be render here. 
      }
于 2017-05-01T19:51:19.403 回答