Create email account with PHP
-
- Posts: 4
- Joined: Wed Jan 20, 2016 5:12 pm
Create email account with PHP
Hi, i want to create email accounts with php usign API of vestacp.
I always get "User account has been successfuly" but the account is not created.
Code: Select all
<?php
// Server info
$vst_hostname = 'domain.com';
$vst_username = 'admin';
$vst_password = 'password';
$vst_returncode = 'yes';
$vst_command = 'v-add-mail-account';
// New account info
$username = 'nicole';
$domain = 'domain.com';
$acount = 'nicol123'; //[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, 'http://' . $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;