How to find the IMEI and serial number of an iPhone before selling it?
You can easily determine the IMEI and the serial number by going to Settings app → General → About and looking for fields named IMEI and Serial Number (along with host of other information).
There's also an Apple support document titled Find the serial number or IMEI on your iPhone, iPad or iPod touch which is worth going through.
The other crucial step to take before giving away your iPhone is to make sure you have synced all your important data (Contacts, Photos, Notes etc.) to iCloud. Also, make sure to create a backup of your iPhone if you wish to restore it to a new iPhone. The backup can be created either on iCloud or an Mac or a Windows computer using iTunes.
Once you have backuped up all the important user data, make sure you sign out of iCloud. To sign out of iCloud, go to Settings app, tap on your name shown with profile picture (this should be the first item just below the Search bar), scroll down and tap on Sign Out (last item shown in red).
You may also be asked to turn off Find My iPhone. Do so by tapping on iCloud on the same screen and than tap on Find My iPhone. Toggle to turn off the switch shown in front of Find My iPhone.
When signing out, iPhone prompts you to choose between deleting or keeping data (Contacts, Notes, Reminders etc.) locally on device. It is recommended to delete the data from device as you are giving it away. As an extra security measure, it's recommended to factory reset the device. Do so by going to Settings app → General → Reset and tap on Erase All Content and Settings. You may be prompted to provide the device passcode.
Once the device is erased, do not set it up again before giving away. It is possible to see the IMEI number even on an iPhone that isn't setup.
It's recommended to go through the Apple support document What to do before you sell, give away, or trade in your iPhone, iPad, or iPod touch and make sure to follow all the official guidelines.
Just type *#06# from you iphone to get your IMEI no.