arduino gsm door alarm

Those while loops to read the doorContactPin state are too confusing. All you need to do is detect a transition from open to closed or from closed to open.

  val = digitalRead(doorContactPin);
  while(val == LOW){
    val = digitalRead(doorContactPin);
  }

This looks like you want loop() to block (do nothing) until the door is opened. Why? What if you decide that you also want to monitor a window? Then, you're screwed because you will end up blocking until the door is opened and the window is opened. Not a good idea.

  time = 0;
  while((val == HIGH)&&(time < time_threshold)){
    time = time + 100;
    val = digitalRead(doorContactPin);
    delay(100);
    digitalWrite(ledPin,HIGH);  
  }

Opening and closing the door within 3 seconds doesn't count as an entry?

When a pin, such as doorContactPin, is INPUT, writing HIGH or LOW to the pin turns on or off the pullup resistor. Why you want to do that in loop is a mystery.

Put your code to send the SMS in a function. Define your requirements for sending an SMS. It appears that you only want to send an SMS if the door is open for 3 seconds or more.

So, detect the transitions from closed to open and from opened to closed. When they happen, record the time. When the SMS is sent, clear the times. When the times are less than 3 seconds apart, clear the times.

unsigned long doorOpenTime = 0;
unsigned long doorClosTime = 0;

int currDoorState;
int prevDoorState = LOW; // Assumes that LOW means closed and that the door is closed when the Arduino starts

void loop()
{
   currDoorState = digitalRead(doorContactPin);
   if(currDoorState != prevDoorState)
   {
     // Door was closed and is now open or door was open and is now closed
     if(currState == LOW)
     {
        // Door is now closed
        doorClosTime = millis();
     }
     else
     {
        // Door is now open
        doorOpenTime = millis();
     }
   }
   prevDoorState = currDoorState;

   // Now see if the door was opened
   if(doorOpenTime > 0)
   {
      // It was. Was it closed?
      if(doorClosTime > 0)
      {
         // Yes. How far apart?
         if(doorClosTime - doorOpenTime >= time_threshold)
         {
            SendSMS("Door closed after more than 3 seconds");
            doorOpenTime = 0;
            doorClosTime = 0;
         }
      }
      else
      {
         // Door is still open. How long has it been open?
         if(millis() - doorOpenTime >= time_threshold)
         {
            SendSMS("Door still open after more than 3 seconds");
//         doorOpenTime = 0;
//         doorClosTime = 0;
         }
      }
   }
}

You can see that there are two places where an SMS is sent, for two different reasons. Either or both may be important to you. You may care, or not, that the door was finally closed. If so, leave them both in, and leave the door times commented out in the second block. If not, remove the first block containing the SendSMS() call, and uncomment the door time resets in the second block.