Emulate form submission with PHP

219 views Asked by At

I am trying to create a link in a PHP generated e-mail to the UPS tracking page. The form on their page for submitting the tracking numbers works like this:

<form action="http://wwwapps.ups.com/WebTracking/track" method="post">
    <input type="hidden" name="trackNums" value="'.$returnIn->getOutgoingTrackingNumber().'"/>
    <input type="submit" name="track.x" value="'.$returnIn->getOutgoingTrackingNumber().'" class="linkButton"/>
</form>

And if I replicate this on my own site it works fine :)

The problem is if I want to put this in an e-mail... Outlook won't handle forms so I created a link to a redirect page hosted on our webserver like this:

<a href="email_tracking_link.php?ups=TRACKINGNUMBER">TRACKINGNUMBER</a>

Now on the email_tracking_link page I need to submit this form AND FORWARD THE USER to the page. I can submit the form using cURL or file_get_contents, but this then renders the page within my own site, without any of the CSS styling etc on the UPS page. My code currently looks like this:

if (isset($_GET['ups']))
    {
    $url = 'http://wwwapps.ups.com/WebTracking/track';
    $data = array('trackNums' => $_GET['ups'], 'track.x' => $_GET['ups']);

    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    }

If I render the form and have the user click the button, then they are forwarded to the UPS page, complete with it's CSS etc. I want this to happen without the user having to click the button...

How can I replicate this behaviour programmatically?

0

There are 0 answers