简体   繁体   中英

Twilio Receiving SMS codeigniter

Hi iam using twilio to send and receive SMS from my customers. The sending SMS works fine.

When a SMS is received i want to save from , Body to my database.its not working. Here is my code.

Controller

function  receive(){
    $post_data['from']       =  $this->input->post('From');
    $post_data['body']       =  $this->input->post('Body');

    if($post_data['from'] && $post_data['body']){
        $this->receive->insert_received_message($post_data);
    }

}

Model

function insert_received_message($data){

     $sms['pone_number']    = $data['from'];
     $sms['message_type']   = 2;
     $sms['body']           = $data['body'];

     $results = $this->db->insert('Sms_message', $sms); 
     return $results;
}

I added the url to my number like this

在此处输入图片说明

Error message in Received log

在此处输入图片说明

Can someone help me to fix this. TNX.

Your data is not save into database make sure your filed name is correct in your array

Controller

function receive() {
    $from = $this->input->post('From');
    $body = $this->input->post('Body');

    if (isset($from) && isset($body)) { //create your insert array like that
        $sms = array(
            'pone_number' => $from,
            'message_type' => 2,
            'body' => $body
        );

        $this->receive->insert_received_message($sms);
    }
}

Model

function insert_received_message($data){

     $this->db->insert('Sms_message', $data); 
     if($this->db->insert_id()>0)// check last insert id
     {
         return $this->db->insert_id();
     }
     else{
         return FALSE;
     }

}

The following link also demonstrates how to interact with messages received.

https://www.twilio.com/docs/quickstart/php/sms/replying-to-sms-messages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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