Jump to content

Variables are not showing in email


jussc
Go to solution Solved by Jacques1,

Recommended Posts

<?php

    if(isset($_POST['amount']))

    {

        $company = $_POST["company"];

        $invoice = $_POST["invoice"];

        $subject = "New Payment";

 

        $recipient = "my@email.com";

 

        $message = "Message from $company with Invoice # $invoice";

 

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

 

        // *********** Payment 

 

        $x_amount = $_POST['amount'];

        $x_login = "don't post sensitive information";  //  Take from Payment Page ID in Payment Pages interface

        $transaction_key = "on a public forum"; // 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);

        die;    

    }

 

?>

 

Hello,

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.

However, I am trying to _POST the other two fields - Company and Invoice - so I can have this information emailed to myself once the client clicks "pay".

 

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 doesn't work - it only shows the text without the variables.

Like: Message from with Invoice # 

Without either variable posting through

 

Is something like this possible? Or am I doing it completely wrong?

Any help would be appreciated!

Justin

Edited by requinix
Link to comment
Share on other sites

Thanks for the response so far!

This is the HTML. This is why I am confused - I am not sure whether it is possible because the target is the payment page...

 

<form action="https://rpm.demo.e-xact.com/payment" method="POST" id="payment" onsubmit="return prepareForm();">

          <input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>
          <input type="hidden" name="x_test_request" value="FALSE"/>
 
          <input name="x_login" id="x_login"  type="hidden" value="">
          <input name="x_amount" id="x_amount"  type="hidden" value="">
          <input name="x_fp_sequence" id="x_fp_sequence"  type="hidden" value="">
          <input name="x_fp_timestamp" id="x_fp_timestamp"  type="hidden" value="">
          <input name="x_fp_hash" id="x_fp_hash"  type="hidden" value="" size="50">
          <input name="x_currency_code" id="x_currency_code"  type="hidden" value="">
 
         <div class="form-group">
            <label for="company">Company Name:</label>
            <input type="text" class="form-control input-lg half" name="company" placeholder="">
         </div>
 
         <div class="form-group">
            <label for="invoice">Invoice #:</label>
            <input type="text" class="form-control input-lg half" name="invoice" placeholder="A12345">
         </div>
 
          <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">
          </div>
 
          <input type="submit" class="btn btn-default" name="submit" id="submitPayment" value="Pay with Hosted Checkout" />
        </form>
Link to comment
Share on other sites

It looks like you're using Javascript (that "prepareForm" bit) to process the form before it gets submitted. That's how the data is being passed to your PHP.

 

So. What's the code for prepareForm? When it constructs the AJAX request to send to your code, does it include the new fields you added?

Link to comment
Share on other sites

here is the function prepareForm

 
    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) {
                $('#x_login').val(data.login); 
                $('#x_amount').val(data.amount); 
                $('#x_fp_sequence').val(data.sequence); 
                $('#x_fp_timestamp').val(data.timestamp); 
                $('#x_fp_hash').val(data.hash); 
                $('#x_currency_code').val(data.currency);
                if(data.hash){
                    makeProcessed(true);
                }
            }
        });
        return processed;
    };
 
i am so glad you can explain this to me in plain english i really appreciate it.
so would the trick be to input in the fields that i have in the HTML as modeled in the function above?
 
thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.