Unlock iphone 4

I want to get my iphone unlocked from the o2 network as im giving it to a friend. I applied online for the unlock code but it says you have no record on the IMEI. A while ago i had to get my iohone replaced with apple so it may be different to the IMEI you have on record, what do i need to do to get it unlocked?