Page 1 of 1

Create email account via php

Posted: Sun Feb 28, 2016 8:36 pm
by Jsnyder01
Hello,

I want to create a service like Gmail can someone please give me an example PHP code to create an email account on VestaCP so users can sign up automatically.

Thank you.

Re: Create email account via php

Posted: Mon Feb 29, 2016 11:53 am
by tjebbeke
You can read the documentation: http://vestacp.com/docs/api/


example code:

Code: Select all

<?php

// Server credentials
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_returncode = 'yes';
$vst_command = 'v-add-mail-account';

// New Account
$username = 'admin';
$domain = 'yourdomain.com';
$acount = 'info'; //[email protected]
$password = 'emailpassword';

// Prepare POST query
$postvars = array(
    'user' => $vst_username,
    'password' => $vst_password,
    'returncode' => $vst_returncode,
    'cmd' => $vst_command,
    'arg1' => $username,
    'arg2' => $domain,
    'arg3' => $acount,
    'arg4' => $password
);
$postdata = http_build_query($postvars);

// Send POST query via cURL
$postdata = http_build_query($postvars);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://' . $vst_hostname . ':8083/api/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$answer = curl_exec($curl);

// Check result
if($answer == 0) {
    echo "User account has been successfuly created\n";
} else {
    echo "Query returned error code: " .$answer. "\n";
}
?>

Re: Create email account via php

Posted: Fri Sep 23, 2016 12:36 pm
by skurudo
API documentation and examples:
http://vestacp.com/docs/API.pdf

CLI commands list and descriptions:
http://vestacp.com/docs/CLI.txt

-> viewtopic.php?f=18&t=12610