Have a look at reed switches. The reed switch is a little set of contacts usually set in a small glass vile that get triggered by a magnet. Basically the contacts open/close (don't recall which) when adjacent to a magnet. These things are usually quite cheap and the contacts are usually impervious to grot as they a sealed in glass. The alternative is a micro switch but these can be difficult to position to get reliable switching but have the advantage of a change over type operation.
To sense a door open/close you mount the reed switch (contacts) on the door frame and the magnet on the door such that when the door is closed the magnet influences the contacts. Then simply wire the contacts into a spare PIO pin and write the code.
Share and Enjoy.