There is a very, very slight chance just erasing it might work, but more likely the iPhone has the previous owner's ID on it which you cannot remove and it may even have an activation lock.
Restore your iPhone, iPad, or iPod to factory settings [with a computer] - "A factory restore erases the information and settings on your iPhone, iPad, or iPod and installs the latest version of iOS or iPod software."
Click here --> http://support.apple.com/HT201252
'Activation Lock for iPhone, iPad, and iPod touch' is a security feature that's designed to prevent anyone else from using an iPhone, iPad, or iPod touch, if it's ever lost or stolen. To learn more click here --> http://support.apple.com/HT201365
For an individual to remove an activation lock absolutely requires the information for the account that applied the lock. Click on this link to learn 'How to remove Activation Lock' --> https://support.apple.com/HT201441
If you do not know the required information and you are not the original owner, get the owner of the account to remove the lock or return the device for a refund or recycle it. The device is otherwise useless to you. If the owner is unknown and has not provided contact information as a message showing in the login screen, there is no way to contact the owner unless the person who gave you the device knows them.