I know this topic has been widely discussed but in this instance I cannot get cURL to submit my simple form and I cannot see why, although I am sure it is obvious. I have tried many different cURL POST data examples found on StackOverflow but none seem to work.
My current idea is that my form action in this case is the problem because it is not, as far as I understand, the real action which posts the data. I have tried various tools to intercept the headers but all I see is the form action I currently have.
I am trying to use cURL to submit the contact form here, http://www.alpinewebdesign.co.uk/
Here is my latest attempt (in which I have included all the hidden fields and tried unsuccessfully I think to set a different header type).
//create array of data to be posted
$post_data['mact'] = 'FormBuilder,m62b34,default,1';
$post_data['m62b34returnid'] = '15';
$post_data['page'] = '15';
$post_data['m62b34fbrp_callcount'] = '1';
$post_data['m62b34form_id'] = '4';
$post_data['m62b34fbrp_continue'] = '2';
$post_data['m62b34fbrp_done'] = '1';
$post_data['name'] = 'Name';
$post_data['email'] = '[email protected]';
$post_data['message'] = 'Message';
$post_data['m62b34fbrp_submit'] = 'Send';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('http://www.alpinewebdesign.co.uk');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
$headers = array();
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
$headers[] = 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryM4YWvE6kIZAIC8vY';
curl_setopt($curl_connection, CURLOPT_HTTPHEADER, $headers);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
Can anyone see the problem?
Thanks
$post_string = http_build_query($post_items);is all you need instead of foreach loop and implode