0

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?

1 Answer 1

1

It's because of this: $text = nl2br($text);

It creates invalid email addresses, which end with <br />. Only the last one is valid, as you don't input new line.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay, then how would I get each line from the textarea and feed it through my loop? I was looking at this post for guidance and that's where I get my previous code from: stackoverflow.com/questions/3702400/get-each-line-from-textarea
Just remove the line, that's it. It's messing up your input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.