Variables are not showing up in email, only text

I am having a bit of trouble in setting up a payment page. I am trying to do two things here.
The form has three fields - Company, Invoice, and Amount.
When the submit button is clicked, the action should take me to a payment page. This part works great. I have tested it on the actual server as well as on MAMP.
However, I am also trying to _POST the other two fields - Company and Invoice - so I can have this information emailed to myself once the client clicks “pay”. (This part is NOT working great).

RIght now, when the button is clicked, it sends me to the payment page (good), and then the email also gets sent (which is also good). However, the email message only shows the text without the variables.
Example: Message from with Invoice #
Without either variable posting through…so the email works but not the variables?

Is something like this possible? Or am I doing it completely wrong?
Any help would be appreciated!

      $company = $_POST["company"];
        $invoice = $_POST["invoice"];
        $subject = "New Payment";
        $recipient = ""; $message = "Message from $company with Invoice # $invoice;

        mail($recipient, $subject, $message);

        $x_amount = $_POST['amount'];
        $x_login = "HCO-JUSTI-373";  //  Take from Payment Page ID in Payment Pages interface
        $transaction_key = "baQH04x6E~IG_cFKAP9S"; // Take from Payment Pages configuration interface
        $x_currency_code = "CAD"; // Needs to agree with the currency of the payment page
        srand(time()); // initialize random generator for x_fp_sequence
        $x_fp_sequence = rand(1000, 100000) + 123456;
        $x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC

        // The values that contribute to x_fp_hash 
        $hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
        $x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);

        $values = array('login' => $x_login, 'amount' => $x_amount, 'sequence' => $x_fp_sequence, 'timestamp' => $x_fp_timestamp, 'hash' => $x_fp_hash, 'currency' => $x_currency_code, 'company' => $company);
        echo json_encode($values);


This is the HTML relevant to it:

        <form action="" method="POST" id="payment" onsubmit="return prepareForm();">

         <div class="form-group">
            <label for="company">Company Name:</label>
            <input type="text" class="form-control input-lg half" name="company" placeholder="">

         <div class="form-group">
            <label for="invoice">Invoice #:</label>
            <input type="text" class="form-control input-lg half" name="invoice" placeholder="A12345">

          <div class="form-group">
            <label for="amount">Amount:</label>
            <input type="text" class="form-control input-lg half" name="x_my_amount" placeholder="123.45" id="x_my_amount">

          <input type="submit" class="btn btn-default" name="submit" id="submitPayment" value="Pay with Hosted Checkout" />

so you’re saying the email is send, you are not using the code above with the syntax error.

just var_dump($invoice).
nothing? try var_dump($_POST['invoice']).
still nothing? try var_dump($_POST).
is it empty? try var_dump($_GET) and tell us was the results are.

also your form is incomplete and does not show the request type.

What is
onsubmit="return prepareForm();"

Might that be messing with the values?

thanks for replying so quickly - appreciate it.
i thought i included everything to highlight the problem - hopefully it still makes sense.
i am using var_dump and outputting to a string to the email.
so…var_dump($invoice) gives me NULL
var_dump($_POST[‘invoice’]) gives me NULL
var_dump($_POST) gives me
array(1) {
string(2) “12”

as i put $12 for the third field (amount), does this mean that the code is only processing the POST for the amount field and not the others?

@Mittineague so that function processes the variables needed to sort the payment portion out. don’t think i can get rid of it, but i am just using the sample code for this payment processor.
i just thought this would be a quick way to get the extra information sent to my email instead.

function prepareForm(){
    $('#submitPayment').val('Please wait ...');

    var processPayment = $.ajax({
        type: 'POST',       
        url: "test.php",
        data: {"amount": $('#x_my_amount').val()},
        dataType: 'json',
        async: false,
        success: function(data) {
    return processed;

as to data: {"amount": $('#x_my_amount').val()}, your JS is not processing the actual form, instead it makes and own request with defined data only, you have to add the value by yourself.

data: {"amount": $('#x_my_amount').val(), "invoice": $('#x_my_invoice').val()},

and give the input the appropriate ID.


@chorn Really appreciate this. It worked like a charm! Thanks for talking me through it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.