Fail with error 'Allowance is not enough' when send token ERC20 in BNB Smart Chain with transferFrom

Hello, I am new to solidity and smart contracts, I would like to create a contract that can send ERC20 tokens from one address to another address. I used this function

function transferFromERC20(IERC20 token, address from, address payable to, uint256 amount) public payable {
        uint256 erc20balance = token.balanceOf(from);
        uint256 erc20allowance = token.allowance(from, address(this));
        token.approve(from, amount);
        require(amount <= erc20balance, "balance is low");
        token.transferFrom(from, to, amount);
        emit TransferSent(msg.sender, to, amount);
    }

but I got the error "Fail with error 'Allowance is not enough'
" When I tried to send transaction, anyone can help me about this I loss a lot of USDT for gas fee when try this

This is a common mistake.

Approval never works this way. Because in the line token.approve(from, amount); your current contract is calling the approve function in the token contract, means the current contract is approving the from address to spend amount tokens.

The only way to work with approvals is to manually approve the contract by calling the approve function with the EOA. Remove the token.approve(from, amount);.

Means the from address should manually call the approve function with this contract's address, and then this transferFromERC20 function should be called