What type of phone is it?
If it's an Android phone there's 3rd party companies that you can pay for an unlock code.
How do you confirm it's locked by T-Mobile? If it's a T-Mobile branded device (e.g. it has "T-Mobile" on it somewhere or when you boot up it says "T-Mobile" in the startup), it's a T-Mobile device (I'm uncertain if there's any devices T-Mobile locked besides iPhones that don't have T-Mobile branding). To find out if it's locked, you.. uh... put a non-T-Mobile SIM in it and try it out (if your cousin was awesome, s/he would have unlocked it before gifting it to you. Think about that next time Christmas comes around and you're shopping for their gift ). If it works, it's unlocked, if it pops up a message complaining invalid SIM or something, it's locked.
if it's been "a long time ago", your cousin wouldn't qualify for an unlock code currently, if it's locked to T-Mobile (your cousin would be the only one eligible to get an unlock code from T-Mobile anyway) -- there's a stipulation that the device must have been used on T-Mobile's network in the previous 45 days -- and "used" means some unknown period of time up to like a week or so.
I agree with gramps28 -- your best bet may be a third party company that provides unlock codes.