Skip to content

Instantly share code, notes, and snippets.

@yasinkuyu
Last active December 28, 2021 06:17
Show Gist options
  • Save yasinkuyu/870452d58a9608a3cb84334f3ddbb689 to your computer and use it in GitHub Desktop.
Save yasinkuyu/870452d58a9608a3cb84334f3ddbb689 to your computer and use it in GitHub Desktop.
Create email account vesta script
<?php
// Server info
$vst_hostname = 'server.vestacp.com';
$vst_username = 'admin';
$vst_password = 'p4ssw0rd';
$vst_returncode = 'yes';
$vst_command = 'v-add-mail-account';
// New account info
$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);
$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);
$data = curl_exec($curl);
if($data == 0) {
echo "User account has been successfuly";
} elseif($data == 4) {
echo "Duplicate account";
} else {
echo "Error: " . $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment