Create email account with PHP through CPANEL

Asked

Viewed 445 times

0

I would like to know if it is possible to create an e-mail account using CPANEL, but not manually, but programmatically?

I need to automate the creation, because manually it would not be possible to account for the demand.

  • 2

    It just depends on how your email system works. Many systems have Apis for this, but each has its own way of working. The way the question looks, there’s an infinite number of answers. You need to [Edit] and be much more specific about the email infrastructure you currently use (and how well you know it).

  • @Bacco, first thanks for the feedback, was receiving several close() and no one had commented, would not know the reason.. Second: I can’t think that there are infinite answers, in my mind it seems clear. Check it out: I have a website, xxx.com, and I want to create an email account on it, for example: [email protected], doesn’t PHP have methods or libraries known for this? I think, Cpanel does that, why can’t I? I thought it was something simpler, as I’m a layman in this, maybe there’s a more complex line of thinking that I’m not able to follow.

  • 2

    The problem has nothing to do with PHP. Email does not use a standard account creation system. Every email system (which has absolutely nothing to do with website hosting) has its own way of creating accounts. A Google email works a certain way, a Microsoft email works another way, my local email system uses a third way, and so on. Surely Cpanel could not create an email on my hosting, for example. The fact is that by chance, who installs Cpanel and releases the creation feature in it, opted for a compatible email system.

  • 2

    Now, after Edit, what you are looking for is this: https://documentation.cpanel.net/display/SDK/Guide+to+cPanel+API+2 - But it still depends on the Cpanel, in this case.

  • @Bacco Thanks, I edited to try not to put the topic in the trash and take the chance to remove the doubt that maybe someone passes or will pass.

1 answer

2


The CPANEL documentation guides you to use the UAPI: https://documentation.cpanel.net/display/SDK/Guide+to+UAPI

Supported version: 11.42 or higher

To create an email account, I’ll show you an example with Liveapi (PHP Class)

// Inclua a library principal do CPANEL
// O local do arquivo varia de acordo com o ambiente. Verifique em qual local está o arquivo no seu ambiente.
require_once '/usr/local/cpanel/php/cpanel.php';

// Instancia o objeto CPANEL. (Faça apenas uma instância)
$cpanel = new CPANEL();

// Aqui invocamos o método uapi informando os parâmetros para criação de conta de email
// Criaremos o email [email protected] com 50mb de quota (espaço limite em disco)
$new_email = $cpanel->uapi(
    'Email', 'add_pop',
    array(
        'email'           => 'sample',
        'password'        => '123456',
        'quota'           => '50', // Caso queira ilimitado, coloque 0 (ZERO)
        'domain'          => 'foo.bar', // domínio
        'skip_update_db'  => '1'
    )
);

When successful returns a string in the format user+domain. In the case of the above example, sample+foo.bar.

Documentation: https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Email%3A%3Aadd_pop

For version 11 up to the current version (legacy): https://documentation.cpanel.net/display/SDK/cPanel+API+2+Functions+-+Email%3A%3Aaddpop

// Create the [email protected] email address.
$add_email_address = $cpanel->api2(
    'Email', 'addpop', 
    array(
        'domain'          => 'foo.bar', 
        'email'           => 'sample', 
        'password'        => '123456',
        'quota'           => '50',
    ) 
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.