How to send XML data using PHP and CURL?

If you are working in a Software Company you may need to know this stuff for sure!.

Do you want to POST XML data to a third party site and get the response from the site?. This code will help you then!


//paste your XML file here

$xml = '

<?xml version="1.0" encoding="UTF-8"?>

// give the path of the Third party site
$url = "";

$ch = curl_init($url);
//curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo $output;




About the Author


Software Engineer, Blogger etc., Visit my Youtube channel - <a href="">Click Here</a>

3 thoughts on “How to send XML data using PHP and CURL?

Leave a Reply

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