I am attempting to send a newsletter registration request to ymlp.com with PHP cURL
An html form works well with this code (I am using ptsv2.com to test POSTing):
<form method="post" action="http://ptsv2.com/t/stacktest/post?id=abcdefghijk">
<input class="text" size="20" name="EMA0" type="text" placeholder="Type your email..." />
<input class="submit" value="Subscribe to Newsletter" type="submit" />
</form>
So I tried mimicking this code in a PHP cURL request with the following code:
<?php
$cURLConnection = curl_init('http://ptsv2.com/t/stacktest/post?id=abcdefghijk');
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLINFO_HEADER_OUT, true);
curl_setopt($cURLConnection, CURLOPT_POST, true);
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, ['EMA0' => 'deleteme@gmail.com']);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array('application/x-www-form-urlencoded'));
$response = curl_exec($cURLConnection);
curl_close($cURLConnection);
And the request is received but the html form's post content type appears as 'application/x-www-form-urlencoded' while the cURL post content type is 'multipart/form-data; boundary=------------------------b9f916145e7d51d3'.
And in the form post both id
and EMA0
appear as parameters, while in the cURL post id
appears as parameter while EMA0
appears as Multipart Value.
Am I providing the headers correctly to cURL ?
Is there any other mistake in my cURL code?
Thank you