cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Sending xml files using curl and php

From: Manish Katiyar <mkatiyar_at_gmail.com>
Date: Thu, 16 Apr 2009 01:18:05 +0530

Hi,

I am a newbie and trying to send an xml file to another php file using
php and curl. I have my xml data in the format below in a file called
temp.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<report>
<Mail>
<Subject>How are you ?</Subject>
<sender_name>user_at_domain.com</sender_name>
<Link>http://someurl.php?rit=1&amp;i=2231608&amp;k=9ac69b4f</Link>
</Mail>
<Mail>
........................
</Mail>
</report>

And I am using the below php file to post xml data.

<?php
$xmldatafile="temp.xml";
function postData($postFields,$url){
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST ,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS ,$postFileds);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
                curl_setopt($ch, CURLOPT_HEADER ,0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
                $data = curl_exec($ch);
                curl_close($ch);
                return $data;
        }

$xmlData = file_get_contents($xmldatafile);
#echo $xmlData;
#$postFileds = 'data='. urlencode($xmlData);
$postFileds = 'data='.$xmlData;

//call function
$result=postData($postFields,"http://localhost/processxml.php");
?>

But for some reason it is not working. The processxml.php is not able
to retrieve the data. I guess this is due to the URL in the xml tag.
Do I need to treat is specially ? I have already removed special
characters from it before putting it into the xml file.

Any help/pointers appreciated.

-Thanks
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-04-15