【问题标题】:using cpanel XML API with PHP to create email使用 cpanel XML API 和 PHP 创建电子邮件
【发布时间】:2017-09-26 19:16:55
【问题描述】:

我正在使用 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 对象([apiversion] => 2 [data] => SimpleXMLElement 对象 ( [原因] => SimpleXMLElement 对象 ( ) [结果] => 1 ) [事件] => SimpleXMLElement 对象 ( [结果] => 1 ) [func] => addpop [module] => 电子邮件)

如果没有,我明白了:

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

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

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

感谢您的帮助和快速响应,谢谢。

【问题讨论】:

    标签: php cpanel cpanel-xmlapi


    【解决方案1】:

    您可以使用如下响应:-

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

       $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. 
          }
    

    【讨论】:

    • 即使没有创建帐户,我也会一直收到“完成”/成功消息
    猜你喜欢
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2013-06-10
    • 2016-08-27
    • 2019-10-16
    • 2020-08-12
    • 1970-01-01
    • 2016-11-29
    相关资源
    最近更新 更多