2

この curl スクリプトについてアドバイスが必要です。FORM から curl スクリプトに値を送信しようとしていますが、curl スクリプトが情報を受信して​​いないようです。

スクリプトは次のとおりです。

<?php
        if($_SERVER['REQUEST_METHOD'] != 'POST') {
            $self = $_SERVER['PHP_SELF'];
    ?>
                      <form method="post" action="<?php echo $self; ?>" class="form-horizontal">
                          <fieldset>
                                <legend>SMS Contact</legend>
                                <div class="control-group">
                                    <label for="basic" class="control-label">Name and Surname</label>
                                    <div class="controls">
                                        <input type="text" name="name" id="name" disabled class='input-square' value="<?php print $contactname;?> <?php print $contactsurname;?>">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="basic" class="control-label">Mobile No</label>
                                    <div class="controls">
                                        <input type="text" name="mobile" id="mobile" disabled class='input-square' value="<?php echo urlencode($contactmobile);?>">
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="textcounter" class="control-label" id="textcounter">Textarea</label>
                                    <div class="controls">
                                        <textarea name="textcounter" id="textcounter" class='input-square span9 counter' data-max="160" rows='6'></textarea>
                                    </div>
                                </div>
                                <div class="form-actions">
                                    <button class="btn btn-primary" type="submit">Send SMS</button>
                                </div>
                          </fieldset>
                        </form>
                        <?php
        } else {

            $mobile = $_POST['mobile'];
            $text = $_POST['textcounter'];
            $username = 'xxxx';
            $password = 'xxxx';

            // Set Timezone
            date_default_timezone_set('Africa/Johannesburg');
            $date = date("m/d/y G.i:s", time());

            // Create Unique ID
            $code = md5(time());
            $newid = $code.$clientid;

            $sql="INSERT INTO sent_itmes (sent_id, sent_message, sent_date, sent_quantity, client_id, sent_mobile)VALUES('$newid', '$text', '$date', '1', '$clientid', '$mobile')";
            $result=mysql_query($sql);

    $url = "http://bulksms.2way.co.za/eapi/submission/send_sms/2/2.0"; // URL to calc.cgi
            $fields = array(
            'site'=>'',
            'username'=>($username),
            'password'=>($password),
            'message'=>urlencode($text),
            'msisdn'=>urlencode($mobile)

                            );
            $fields_string="?";
            //url-ify the data for the POST
            foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
            rtrim($fields_string,'&');

            //open connection
            $ch = curl_init();

            //set the url, number of POST vars, POST data
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
            curl_setopt($ch,CURLOPT_POST,count($fields));
            curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

            //execute post
            ob_start();
            curl_exec($ch);
            ob_end_clean();
            echo '<div class="alert alert-block alert-success">
                                          <a class="close" data-dismiss="alert" href="#">×</a>
                                          <h4 class="alert-heading">Success!</h4>
                                          Your message has been Sent!
                                        </div><br/><br/><a href="search_contact.php" class="btn btn-large btn-round">Search Contact</a>';

            //close connection
            curl_close($ch);
        }
        ?>

フォームを送信すると、応答サーバーから「受信者が指定されていません」というエラーが表示されます。これは、フォームの値「モバイル」が値を介してカールに渡されないことを意味します。

助けてください、頭から離れます。

4

3 に答える 3

2

これを使用してデータを送信します

        //open connection
        $ch = curl_init($url);

        curl_setopt($ch,CURLOPT_POST,count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS,POSTVARS.$fields_string); // this line is edited..
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);


        //execute post
        ob_start();
        curl_exec($ch);

あなたの注文は間違っていました...

詳細http://www.askapache.com/php/sending-post-form-data-php-curl.html

于 2012-09-28T09:56:37.297 に答える
2

投稿するコンテンツと適用するコンテンツを説明するヘッダーを追加してみてください

    curl_setopt ( $ch, CURLOPT_HTTPHEADER, array(
        'Content-type: application/x-www-form-urlencoded',
        'Accept: text/html',
        'Expect: ',
    ) );
于 2012-09-28T09:58:59.927 に答える
1

フィールドが無効になっているフォームを送信すると、そのフィールドは送信されません。

<input type="text" name="mobile" id="mobile" disabled class='input-square' value="<?php echo urlencode($contactmobile);?>">

「モバイル」を送信したい場合は、そのための隠しフィールドを追加する必要があります。そして多分無効なフィールド名を置き換えます

于 2012-09-28T11:51:24.443 に答える