[英]using cpanel XML API with PHP to create email
Im using XML API to cpanel to create email accounts from a PHP page. 我使用XML API来从PHP页面创建电子邮件帐户。
Im having problem with creating a code that will see if the email account was setup successfully or not. 我在创建代码时遇到问题,该代码将查看是否成功设置了电子邮件帐户。
My PHP file looks like this: 我的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 );
?>
If the email account is createde successfully i get this response: 如果成功创建了电子邮件帐户,我将收到以下响应:
SimpleXMLElement Object ( [apiversion] => 2 [data] => SimpleXMLElement Object ( [reason] => SimpleXMLElement Object ( ) [result] => 1 ) [event] => SimpleXMLElement Object ( [result] => 1 ) [func] => addpop [module] => Email )
SimpleXMLElement对象([apiversion] => 2 [数据] => SimpleXMLElement对象([原因] => SimpleXMLElement对象()[结果] => 1)[事件] => SimpleXMLElement对象([结果] => 1)[func ] => addpop [module] =>电子邮件)
If not i get this: 如果没有,我得到这个:
SimpleXMLElement Object ( [apiversion] => 2 [data] => SimpleXMLElement Object ( [reason] => The password that you entered has a strength rating of “23”. You cannot use it because it is too weak... [result] => 0 ) [error] => The password that you entered has a strength rating of “23”. You cannot use it because it is too weak... [event] => SimpleXMLElement Object ( [result] => 1 ) [func] => addpop [module] => Email )
SimpleXMLElement Object([apiversion] => 2 [data] => SimpleXMLElement Object([reason] =>您输入的密码的强度等级为“ 23”。您不能使用它,因为它太弱了... [结果] => 0)[错误] =>您输入的密码的强度等级为“ 23”。您不能使用它,因为它太弱了... [事件] => SimpleXMLElement对象([结果] => 1 )[func] => addpop [module] =>电子邮件)
I tried using this code but didn't work: 我尝试使用此代码,但没有成功:
if ($result->result->status) {
print "Creation of account worked successfully!";
}
else {
print "Creation Failed:" $result->result->statusmsg;
}
I would appreciate help and quick response, thanks. 感谢您的帮助和快速的回复,谢谢。
You can use response as below:- 您可以使用以下响应:
-- to generate a new email address -生成一个新的电子邮件地址
$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.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.