by Qurrat Babar.
sender_id is the $USER->id, the id of the user currently logged in.
The piece of code is as below:
$contact = new stdClass();
$contact->Msg_Id = $sms->Msg_Id;
$contact->sender_id = $USER->id;
$contact->contacts = $phone;
$contact->Date = date("Y-m-d H:m:s");
$contact->Status = 'pending';
$contact->Retrys = '0';
$contact->id = $DB->insert_record("sms_contacts", $contact);
sms_contacts is a custom table in my moodle db.