I'm trying to use curl to perform multiple curl posts to a URL. I have a page with a field for URL and a textarea box where I would put multiple emails (on separate lines) to be posted to the url.
Here's my code.
<?php
$url = $_POST['url'];
$text = trim($_POST['emails']);
$text = nl2br($text);
$text = explode("\n", $text);
foreach($text as $i => $text) {
$fields = array(
'u' => urlencode('0000'),
'id' => urlencode('0000'),
'FIELD0' => urlencode($text),
'FIELD1' => urlencode('First'),
'FIELD2' => urlencode('Last')
);
$fields_string = "";
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
$mh = curl_multi_init();
$ch[$i] = curl_init();
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($mh, $ch[$i]);
curl_setopt($ch[$i],CURLOPT_URL, $url);
curl_setopt($ch[$i],CURLOPT_POST, count($fields));
curl_setopt($ch[$i],CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch[$i]);
curl_close($ch[$i]);
}
?>
As it stands now, if I put one email into my field, it works. But when I put multiple emails into the field, it only posts the last one. Can someone help out?