Yii 2.0: yii2-cpanel-email-creator

With this extension you will be able to easly programatically create,update,delete cPanel mail account from yii2-app
1 follower

With this extension you will be able to easly programatically create,update,delete cPanel email account from your yii2 application.

With this component you are able to:

  • Create new mail accounts

  • Change existing account disk quota

  • Change existing accounts their passwords

  • Delete accounts

Requirements

Yii 2.0 or above

Installation

The preferred way to install this extension is through composer.

After you have installed composer to install this component you need to run:

php composer.phar require --prefer-dist filipajdacic/yii2-cpanel-email-creator "*"

or add to the require section in your composer.json file this line:

"filipajdacic/yii2-cpanel-email-creator": "*"

Usage

Once the extension is installed, just add in your config file:

'components' => array(
    ...
    'cpanelemailcreator' => array(
        'class' => 'filipajdacic\cpanelemailcreator\EmailCreator',
        'ip' => 'YOUR_CPANEL_SERVER/HOST_IP_ADDRESS',
        'port' => '2083', // it can be also 2086
        'cpanel_username' => 'YOUR_CPANEL_USERNAME',
        'cpanel_password' => 'YOUR_CPANEL_PASSWORD'
    ),
    ...
);

and enter your params like ip, port, cpanel username and password.

After you have configured component you can finally use like this:

1. Create a new mail account:

$domain = "mywebsite.com";
$email_username = "john.doe";
$email_password = "myaccountpassword123!";
$email_quota = 500; // in MB
 
$create_mail_account_result = Yii::$app->cpanelemailcreator->createNewAccount(
    $domain, 
    $email_username, 
    $email_password, 
    $email_quota
);
 
if($create_mail_account_result) {
    $result =  "Mail account ".$email_username."@".$domain." is created.";
} else {
    $result =  "Mail account is not created. Reason:".$create_mail_account_result;
}
 
echo $result;

2. Change existing email account password:

$domain = "mywebsite.com";
$email_username = "john.doe";
$email_new_password = "mynewaccountpassword123$";
 
 
$change_password_result =   Yii::$app->cpanelemailcreator->changeAccountPassword( 
                                        $domain, 
                                        $email_username, 
                                        $email_new_password
                            );
 
if($change_password_result) {
    $result = "Mail account password for ".$email_username." is changed.";
} else {
    $result = "Password is not changed. Reason:".$change_password_result;
}
 
echo $result;

3. Change existing email account disk quota:

$domain = "mywebsite.com";
$email_username = "john.doe";
$email_new_quota = "10000"; // in MB
 
$change_mail_quota_result =     Yii::$app->cpanelemailcreator->changeEmailQuota( 
                                        $domain, 
                                        $email_username, 
                                        $email_new_quota
                                );
 
if($change_mail_quota_result) {
    $result = "Mail quota for ".$email_username." is changed to ".$email_new_quota." MB.";
} else {
    $result = "Mail quota is not changed. Reason:".$change_password_result;
}
 
echo $result;

4.Deleting existing email account:

$domain = "mywebsite.com";
$email_username = "john.doe";
 
$delete_mail_result =   Yii::$app->cpanelemailcreator->deleteMailAccount( 
                                        $domain, 
                                        $email_username, 
                                        $email_new_quota
                        );
 
if($delete_mail_result) {
    $result = "Mail account ".$email_username."@".$domain." is deleted."; 
} else {
    $result = "Mail account is not deleted. Reason:".$change_password_result;
}
 
echo $result;

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet