Well, we're not alone: various animals, mostly mammals, but also birds, reptiles, fish, etc. have been thoroughly documenting as exhibiting similar behaviors that humans do when they would be experiencing human emotions, and psychologists and physiologists have identified that they also experience the same brain activity, changes in body chemistry, etc. while doing so. Some mollusks (the group that contains squids, cuttlefish, and octopus, in particular) have also been shown to have emotion-like behaviors, although because their blood, brains and body chemistry have evolved entirely, convergently relative to that in mammals and other vertebrates, we can't measure their bodies' reactions to see if it is comparable to that which we feel, but the evidence is strong that they do feel something very similar to what we think of as emotion.
Given the evidence, both in convergent evolution and from how widespread emotions are in animals, we have to conclude that they have survival value. How, why, and when all of this began in our evolutionary past are unresolved questions in evolutionary psychology.
How it all works mechanically, as in what chemicals in the brain and blood do what, it is still hard to understand for scientists, but I do know that a lot of work is being done on it, and I also know that it's going to work very differently in squids, octopus, etc., than it does in us. Our last common ancestor with a squid had no blood to circulate hormones through, and didn't have much of a brain either.