How To Make A POST Request with PHP and cURL


Improve your writing skills in 5 minutes a day with the Daily Writing Tips email newsletter.

Below you’ll find the PHP code to make a simple POST request using cURL. You can send the POST request either to your own server/domain, or to an external one, though it’s not guaranteed the external host will accept your POST.

<?php
                $name = "John Doe";
                $email = "johndoe@hotmail.com";
                $url = "http://www.domain.com/signup/";

                $fields = "name=$name&email=$email";

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, 1);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
         ?>

One thought on “How To Make A POST Request with PHP and cURL

Leave a Reply

Your email address will not be published. Required fields are marked *