Creatures can attack ships with spells. Ships are somewhere between creatures and objects, sort of like constructs, so spells will often affect ships in different ways or in some cases, not at all. However, because a ship is actively crewed and piloted, it can make saving throws against spell effects. Ships are immune to most spells that require a mental (Intelligence, Wisdom, Charisma) save. The DM has information to cover these situations as they arise.
A document containing some flavorful, campaign-specific homebrew spells can be found here.