How to interface GSM with 8051 microcontroller to send SMS?
(While this answer perhaps might seem rude it is not meant to be. It is just a b) style answer).

You should never, never, never, ever use delay, sleep or similar to wait for the respose from the modem! In the same way you hopefully never would think of writing a web browser that ignores all responses the web server sends back to you, you should never think of writing a modem communication program that ignores all responses the modem sends back to you.
You MUST change your algorithm to the following:
send_at_command(&quot;AT+WHATEVER\r&quot;);
do {
    line = read_full_line();
} while (!is_final_result_code(line));

where read_full_line reads characher by character until it receives \n and the previous character was \r (assuming V1 format1).
You can look at the code for atinout for an example for the is_final_result_code function (you can also compare to isFinalResponseError and isFinalResponseSuccess in ST-Ericsson's U300 RIL, although note that CONNECT is not a final result code, it is an intermediate result code, so the name isFinalResponseSuccess is not 100% correct).
Also, specifically for AT+CMGS, you MUST wait for the \r\n&gt;  response from the modem before you start sending the payload. See the first part of this answer for more details.

1
See 6.2.6 DCE response format in V.250. You should not change this to V0, even if it might seem tempting to only having to check for a single character at the end of final result codes, but because information text have always \r\n as EOL, and you are just way better of treating all lines in the same way.