简体   繁体   English

使用curl_multi的多个curl帖子

[英]Multiple curl posts using curl_multi

I'm trying to use curl to perform multiple curl posts to a URL. 我正在尝试使用curl对URL执行多个curl发布。 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. 我有一个页面,其中包含用于URL的字段和一个textarea框,在其中将多封电子邮件(放在单独的行中)发布到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? 有人可以帮忙吗?

It's because of this: $text = nl2br($text); 这是因为: $text = nl2br($text);

It creates invalid email addresses, which end with <br /> . 它创建了以<br />结尾的无效电子邮件地址。 Only the last one is valid, as you don't input new line. 由于您不需要输入新行,因此只有最后一个有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM