Multiple recipients of POST data

Hi guys. Using PHP, I currently capture form data to a database and then email the contents. This is no issue, when the form is submitted, it calls the script that does the field validation/sanitization and posts to a SQL DB, then processes the mail using PHPMailer library.

What I now also want to do is send the form data to a 3rd party application, hosted elsewhere, but I have never done this before.

I have no real experience of using cURL, but my research (Google) would suggest that this might be the best way to go?
I believe that if it was data only, I could use cURL to post an encoded JSON object, but as the form data will most likely have an image file attachment, I would need to send as POST data?

Appreciate your input/guidance in advance.

/Danny

This blog post gives some details. The pertinent bit of code is:

$ch = curl_init('https://www.some-url.com');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = array(
    'some_file' => new CURLFile('/path/to/your/upload.png'),
    'some_data' => 'you can put your other data in this array as well',
    'some_more_data' => 'like so'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$r = curl_exec($ch);

curl_close($ch);

Thanks. It looks like that piece of script can also sit in the form handler file, along with the post to db and PHPMailer script.

Sponsor our Newsletter | Privacy Policy | Terms of Service