Вы правы:
Both types of message consist of a start-line, zero or more header fields (also known as «headers»), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.
Значит надо отлаживать — смотреть, что пришло в $data.