我使用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] =&gt; 2 [data] =&gt; SimpleXMLElement对象([reason] =&gt; SimpleXMLElement对象() [result] =&gt; 1)[event] =&gt; SimpleXMLElement对象([result] =&gt; 1) [func] =&gt; addpop [module] =&gt;电子邮件)
如果不是,我明白了:
SimpleXMLElement Object([apiversion] =&gt; 2 [data] =&gt; SimpleXMLElement 对象([原因] =&gt;您输入的密码具有强度 评分为“23”。你不能使用它,因为它太弱了...... [结果] =&GT; 0)[错误] =&gt;您输入的密码的强度等级为“23”。你不能使用它,因为它太弱了...... [event] =&gt; SimpleXMLElement对象([result] =&gt; 1)[func] =&gt; addpop [module] =&gt; 电子邮件)
我尝试使用此代码但不起作用:
if ($result->result->status) {
print "Creation of account worked successfully!";
}
else {
print "Creation Failed:" $result->result->statusmsg;
}
非常感谢帮助和快速回复,谢谢。
答案 0 :(得分: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.
}