0

I have a piece of code which do a fsockopen

      $url = 'http://abcd.com/def';
      $post_params[0] = 'eids='.urlencode($email);
      $post_params[1] = 'mhead='.urlencode($head);
      $post_params[2] = 'mcontent='.urlencode($content);
      $post_string = implode('&', $post_params);
      $parts=parse_url($url);
      $fp = fsockopen($parts['host'],isset($parts['port'])?$parts['port']:80,$errno, $errstr, 30);
      $out = "POST ".$parts['path']." HTTP/1.1\r\n";
      $out.= "Host: ".$parts['host']."\r\n";
      $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
      $out.= "Content-Length: ".strlen($post_string)."\r\n";
      $out.= "Connection: Close\r\n\r\n";
      if (isset($post_string)) $out.= $post_string;
      fwrite($fp, $out);
      fclose($fp);
      return 1;

I was trying to convert it to cURL, but couldn't success

Here is what i did

        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL, "http://abcd.com/def");
        curl_setopt($ch, CURLOPT_POSTFIELDS, array(
                'eids' => urlencode($email),
                'mhead' => urlencode($head),
                'mcontent' => urlencode($content)
            ));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));
        curl_setopt($ch, CURLOPT_TIMEOUT, 2); 
        $response = curl_exec($ch); 
        curl_close($ch);   

        return $response;

Any idea?

void
  • 36,090
  • 8
  • 62
  • 107
  • _but couldn't success_ - Be more specific. – Federkun Sep 27 '15 at 23:45
  • @Leggendario So the server is not handling my request the way it suppose to, it is a script which sends mail, If i am using fsockopen it is sending it successfully but not in case of cURL (giving error "Mail Not Sent") – void Sep 27 '15 at 23:47

0 Answers0