How to split the funds and send X% to fee wallet and the remaining funds to another wallet? Anybody have any idea about how to do it? 


User send the bitcoins
X% goes to fee wallet
remaining funds goes to service wallet




I'm trying to use the "sendfrom" but it's not working because he only send the fee amount (or the first call), never the rest.

$sendingFee = $bitcoin-&gt;sendfrom($account, $addFee, $feeFormated, 0);
$sendingRest = $bitcoin-&gt;sendfrom($account, $addRest, $restMath, 0);


This is my code:

&lt;?php

require("easybitcoin.php");
$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

function fee($fee, $bal){
    $final = ($fee / 100) * $bal;
    return $final;
}

#account
$account = "pizza";

#fee address
$addFee = "2N9xQyV6itnZNBv5NSLUy8ffXcfopVvP19v";

#Rest address
$addRest = "2MtEzMsT9eedTms9ivEQnjuHPRWw1DHnxyT";

#% charged
$tax = 10;

#balance
$balance = $bitcoin-&gt;getbalance($account, 1);

#do a math to remove X%
$feeMath = fee($tax, $balance);

#I was receiving "invalid amount" error. Fixed with this, I was giving 9 instead of 8 after zero. See satoshis for more.
$feeFormated = number_format($feeMath, 8);

#remove the fee from current balance
$restMath = $balance - $feeFormated;

#send the fee to the address xxxx
$sendingFee = $bitcoin-&gt;sendfrom($account, $addFee, $feeFormated, 0);

#send the balance minus fee to the address yyy
$sendingRest = $bitcoin-&gt;sendfrom($account, $addRest, $restMath, 0);

$err = $bitcoin-&gt;error;

#Print message for control
print_r("Fee &lt;b&gt;TXID&lt;/b&gt; = " . $sendingFee . " Amount sent = " . "&lt;b&gt;" . $feeFormated . "&lt;/b&gt;&lt;br&gt;&lt;br&gt;");
print_r("Rest &lt;b&gt;TXID&lt;/b&gt; = " . $sendingRest . " Amount sent = " . "&lt;b&gt;" . $restMath . "&lt;/b&gt;&lt;br&gt;&lt;br&gt;");

print_r("It's not working because: " . $err);

echo var_dump($sendingFee) . "&lt;br&gt;&lt;br&gt;";
echo var_dump($sendingRest) . "&lt;br&gt;&lt;br&gt;";


?&gt;


It's not perfect (far from this) but please understand, I'm not a php guy, even a programmer, I'm just working in a personal project as a hobby. 

Maybe should I use "sendmany"? If so, how to use this with php? I saw some examples on internet but nothing showing how to use with php and variables. 

Thanks in advance.
Problem solved using "sendmany":

&lt;?php
#SENDMANY WORKING
require("easybitcoin.php");
$bitcoin = new Bitcoin("root", "000000", "localhost", "18332");

$account = "pizza";

$arrayRec = array("2MsWztzmaxnsU3xetrKsD4E9ep4r2gYtXj9" =&gt; "0.00111", 
                "2Mt7dkQiyExrNQTXu9D3qoCpWg3J5TJy9Up" =&gt; "0.00222" );

$send = $bitcoin-&gt;sendmany($account, $arrayRec);

print_r($send);

?&gt;