发送短信后标头不起作用

时间:2017-05-18 09:33:31

标签: php html

我有一个发送短信的脚本,它的工作正常,但之后它没有重定向到我的下一页。我想要实现的是发送正在工作的短信,然后在短信发送后立即重定向到另一个页面。这是我的代码:

class MyMobileAPI
{

public function __construct() {
    $this->url = 'http://smsgateway';
    $this->username = 'username'; //your login username
    $this->password = 'password'; //your login password
}



public function sendSms($mobile_number, $msg) 
   { 
        $data = array(
           'Type' => 'sendparam', 
           'Username' => $this->username,
           'Password' => $this->password,
           'numto' => $mobile_number, //phone numbers (can be comma  seperated)

            'data1' => $msg, //your sms message

        );
        $response = $this->querySmsServer($data);
       return $this->returnResult($response);
    }

    // query API server and return response in object format
   private function querySmsServer($data, $optional_headers = null) 
    {

        $ch = curl_init($this->url);
        curl_setopt($ch, CURLOPT_POST, true);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // prevent large delays in PHP execution by setting timeouts     while connecting and querying the 3rd party server
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000); // response wait time
            curl_setopt($ch, CURLOPT_TIMEOUT_MS, 2000); // output response time
        $response = curl_exec($ch);
        if (!$response) return NULL;
        else return new SimpleXMLElement($response);
    }

    // handle sms server response
}

    //Execute script
    $test = new MyMobileAPI();
    $test->sendSms("$mobile_n","$msg"); //Send SMS
    $test->checkcredits(); //Check your credit balance
    enter code here
    header( 'Location:check.php' );

0 个答案:

没有答案