我无法通过PHP-Curl发布和重定向到支付网关

I have built a form that requires the info ,including $amount.

Supposedly , the form will post the info to the MYSQL Db for storing . <form name="payFormCcard" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">

For the PHP part , some payment info(e.g. $amount ,some info will be posted in hard coded form ) will post to Payment Gateway via Curl. And I will redirect to the Payment Gateway compulsorily header("Location:https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");

Now , the data can save into the DB successfully .Although it goes to the Payment Gateway at the end ,the data cannot post to the Gateway .

One the Gateway site ,

Error Message

Parameter merchantId Incorrect

Hence , sth is wrong on the Curl method .All parameters cannot pass to the payment Gateway successfully .

PHP Part in the create.php:

// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Validate name
    $input_CName = trim($_POST["CName"]);
    if (empty($input_CName)) {
        $CName_err = "Please enter a name.";
    } elseif (!filter_var(trim($_POST["CName"]), FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z'-.\s ]+$/")))) {
        $CName_err = 'Please enter a valid name.';
    } else {
        $CName = $input_CName;
    }
....Other field validation ...

....Storing to DB if every field is okay .
  if (empty($CName_err) && empty($Address_err) && empty($amount_err) && empty($Phone_err)) {
        // Prepare an insert statement
        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "INSERT INTO donation (CName, Address, Phone, Amount ,Ticket, Purpose) VALUES (?, ?, ?, ? ,?, ?)";

        $q = $pdo->prepare($sql);
        $q->execute(array($CName, $Address, $Phone, $amount ,$Ticket ,$Purpose));
        Database::disconnect();

Curl Part ......

$fields = array(
   'amount' => $amount,
      'merchantId'   => 'sth',
            'orderRef'    => 'sth',
            'currCode'   => '344',
            'mpsMode'    => 'NIL',
       'successUrl' =>'http://www.yourdomain.com/Success.html',
 'failUrl' =>'http://www.yourdomain.com/Fail.html',
'cancelUrl'=>'http://www.yourdomain.com/Cancel.html',
            'payType'    => 'N',
            'lang'       => 'E',
            'payMethod'  => 'CC',
            'secureHash'=> 'sth'
);

// build the urlencoded data
$postvars = http_build_query($fields);
    $ch = curl_init();
//
curl_setopt($ch, CURLOPT_URL,"https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp");
curl_setopt($ch, CURLOPT_POST,  count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
//
//// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);

   header("Location:https://test.paydollar.com/b2cDemo/eng/payment/payForm.jsp"); 
}

}
?>