Okay, are the [url] tags there because they're supposed to be? Meaning that you've got some sort of BBCode processor on $msg?
I'm guessing that if you're putting the BBCode in there, that's where it's going wrong, but if not, then it's something else before line 88.
I changed your post to use [php][/php] tags.