I'm using an API to post XML request in WordPress. I wrote this code and I typed it in function.php but I get an error:
Cannot redeclare createRequestXML() (previously declared in /home/aquamahi/public_html/wp-content/themes/topcommerce/functions.php:1641) in /home/aquamahi/public_html/wp-content/themes/topcommerce/functions.php on line 1639
and line 1639 is: function createRequestXML()
$user = get_users();
foreach($user as $item){
$URL = 'http://api.payamak-panel.com/post/Contacts.asmx';
function createRequestXML() {
$first_name = get_user_meta($item->id,"first_name",true);
$last_name = get_user_meta($item->id,"last_name",true);
$xml = ' <?xml version="1.0" encoding="UTF-8" ?>
<SecurityInfo>
<Username>09212395651</Username>
<Password>M@hiPet@12345</Password>
</SecurityInfo>
<Lead>
<GroupIds>571566</GroupIds>
<FirstName>'.$first_name.'</FirstName>
<LastName>'.$last_name.'</LastName>
<MobileNumber>'.$item->login.'</MobileNumber>
<BirthDate>01/01/1300</BirthDate>
<Gender>2</Gender>
<Province>021</Province>
<City>021</City>
<AdditionalDate>1/1/1300</AdditionalDate>
</Lead>';
return str_replace("\n","",$xml);
}
$send = createRequestXML();
try {
$client = new SoapClient("http://api.payamak-panel.com/post/Contacts.asmx?wsdl",array(
'location' => $URL,
'uri' => "http://www.reefservices.co.uk/leadws/",
'trace' => 1,
'exceptions' => true
));
$return = $client->Submit(array('Data' => $send));
echo '<pre>';
print_r($return);
echo '</pre>';
} catch(SoapFault $e) {
echo '<h3>Exception</h3>';
echo '<pre>';
print_r($e);
echo '</pre>';
}
}