1

I am currently using this code to POST a form's data to https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx:

<script type="text/javascript">

        $(document).ready(function(){
            $("#textnextofkin").validate({
                debug: false,
                rules: {
                    name: "required",
                    email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    name: "Please let us know who you are.",
                    email: "",
                },
                submitHandler: function(form) {
                    // do other stuff for a valid form
                    $.post('http://www.example.co.uk/erc/process2.php', $("#textnextofkin").serialize(), function(data) {
                        $('#results').html(data);
                    });
                }
            });
        });

</script>

    <form name="textnextofkin" id="textnextofkin" method="POST" action="">
        <div class="hiddenfields">
            <p>Username:<br>
                <input name="EsendexUsername" type="text" value="AAAAA"></p>
            <p>Password:<br>
                <input name="EsendexPassword" type="password" value="AAAAA"></p>
            <p>Account:<br>
                <input name="EsendexAccount" type="text" value="AAAAA"></p>
            <p>Send Name<br>
                <input name="EsendexOriginator" type="text" value="example"></p>
            <p>Recipient:<br>
                <input name="EsendexRecipient" type="text" value="01234123456"></p>
            <p>Message:<br>
                <input name="EsendexBody" rows="3" cols="20" value="Hello test message"></p></div>
                <input type="submit" class="email-buttons" name="submit" value="Text next of kin">
    </form>

process2.php:

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=AAAAA&EsendexPassword=AAAAA&EsendexAccount=AAAAA&EsendexRecipient=01234123456&EsendexBody=test"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);

    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

I need to alter this so that I can POST the form data to process.php instead, and then use process.php to send the information to the Esendex website. I need to do this because process.php contains data I need to include in the form (e.g. $_SESSION['first_name'] ). I suppose I will need to change the Esendex URL above to process.php, but then I don't know what to enter into the process.php page to send the information it recieves.

Could someone please help me to do this?

Thanks for any help

Daniel H
  • 2,865
  • 8
  • 34
  • 32
  • possible duplicate of [PHP - Redirect and send data via POST](http://stackoverflow.com/questions/3045097/php-redirect-and-send-data-via-post) – eykanal May 11 '11 at 13:05

2 Answers2

1

You post all stuff with ajax to process.php. there you get all variables out of the $_POST array and append your fields.

Then you could use curl to repost to esendex and catch the result, which you then return.

Prikkeldraad
  • 1,347
  • 9
  • 14
  • Would you mind explaining how I would use CURL please? I have had a look at that documentation for it but don't really understand it. Also, I don't need to get a reply from the Esendex website, I just need to send data to it. Thanks – Daniel H May 11 '11 at 13:14
  • Curl has a bit of a learning curve, but please try to implement some examples from http://nl2.php.net/curl. It will make you learn more then if i copy paste the solution for you. Keep in mind that for posting you need CURLOPT_POST and CURLOPT_POSTFIELDS. – Prikkeldraad May 11 '11 at 13:35
1

The most important you need to know is that you need curl to be enabled, before you can use the code below. Curl is usually enabled, but its worth checking

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);

    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

EDIT

try this code instead

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt( $curl_handle, CURLOPT_SSL_VERIFYPEER, false );  //so we can post to https  
    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

The above code is just a snippet, so i did not pass all $data as you can see, so you will have to make it more complete. Place the code in process.php and it should send the data to Esendex website.

EDIT I would advise that you read up on CURL to really understand whats going on in the code above. A good starting point would be the php.net site

boug
  • 1,859
  • 1
  • 13
  • 13
  • Hi boug, thanks for your help. I have updated my post with what I have now, but for some reason it doesn't seem to be sending the data to the Esendex website. Am I doing something wrong? – Daniel H May 11 '11 at 13:50
  • are you getting any error messages? could you also update your question including your code – boug May 11 '11 at 13:57
  • no I'm not getting any error messages. I have updated my question with the code I'm using – Daniel H May 11 '11 at 14:01
  • Ok, the next thing you need to check is if curl is enabled. Are you developing on localhost or using WAMP, LAMP etc? – boug May 11 '11 at 14:04
  • I made a test page with phpinfo() in and it says that Curl is enabled, and the version is 7.19.4. Edit: I'm doing it on the internet as well, not locally – Daniel H May 11 '11 at 14:07
  • Oh, I think I might know what is causing the problem. Notice that you are sending to a https. This requires a slightly different code. Will post edit in answer shortly – boug May 11 '11 at 14:13
  • Thanks very much boug, that works perfectly :D I'll make sure to read up on curl, it seems pretty useful! – Daniel H May 11 '11 at 14:21