在Bluehost CPanel中使用PHP脚本创建电子邮件帐户

时间:2019-05-30 14:00:37

标签: php cpanel bluehost cpanel-xmlapi

我正在尝试在bluehost服务器中使用PHP脚本创建电子邮件帐户。我尝试了许多脚本,但响应为“访问被拒绝”或file_get_contents(https://...@example.com:2083/frontend/x3/mail/doaddpop.html?email=username@example.com&domain=example.com&password=password&quota=25):打开流失败:HTTP请求失败! HTTP / 1.0 401访问被拒绝。支持小组说,他们根本没有任何限制。我的代码:

脚本1:

include ("xmlapi.php"); 

$account    = "domain.com"; 
$account_pass   = "domainpass";

$email_user = "username@domain.com";
$email_password = "Mailpassword";
$email_domain   = "domain.com"; 
$email_quota    = '0';

$xmlapi = new xmlapi('xxx.xxx.xxx.xxx'); 
$xmlapi->password_auth($account, $account_pass);
$xmlapi->set_output('xml');

echo $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );

脚本2:

 $f = fopen ("https://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass&quota=$equota", "r");

 $error = error_get_last();
 echo "HTTP request failed. Error was: " . $error['message'];

 if (!$f) {
 $msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
 break;
 }

脚本3:

$result = $xmlapi->api2_query($cpanel_username, 'Email', 'addpop', $api2args);

脚本4:

 include ("cpaneluapi.class.php");
 $cpanel = new cpanelAPI(); // Connect to cPanel - only do this once.
 //$cPanel = new cpanelAPI('domain.com', 'Password', 'cpanel.domain.com');

 // Create the user@example.com email address.
 $new_email =  $cpanel->curl_request('https://example.com:2087/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addpop&domain="example.com"&email="user"&password="12345luggage"&quota="500"');

 // $new_email = $cpanel->api2(
 //     'Email', 'add_pop',
 //     array(
 //         'email'           => 'user',
 //         'password'        => '12345luggage',
 //         'quota'           => '0',
 //         'domain'          => 'example.com',
 //         'skip_update_db'  => '1',
 //         )
 // );
 echo $new_email;

1 个答案:

答案 0 :(得分:-1)

<?php
include "cpaneluapi.class.php";
$cPanel = new cpanelAPI('username-cpanel', 'password-cpanel', 'hostname-cpanel');
$response = $cPanel->api2->Email->addpop(['email' => 'username-email', 'domain' => 'domain-email', 'quota' => '50', 'password' => 'password-email']);
var_dump($response);
?>

来源:https://github.com/N1ghteyes/cpanel-UAPI-php-class