An erection is a manly miracle—a complex, coordinated effort of brain, blood vessels, nerves, muscles and hormones that increases blood flow to the penis sixfold. But because so much has to go right for a man to have an erection, there’s also a lot that can go wrong.

The problem is called erectile dysfunction (ED)—the inability to get or sustain an erection hard enough to have enjoyable and satisfying sex. And it’s a very common problem. Nearly one in five men have ED, including 44% of men ages 60 to 69 and 70% of men 70 and older.

A prescription ED drug such as sildenafil (Viagra), vardenafil (Levitra) or tadalafil (Cialis) can help. But this pharmaceutical solution isn’t necessarily the best solution, because ED drugs don’t address the underlying causes of ED—some of which can kill you.

What most men don’t realize: An erection is the best barometer of a man’s overall health—particularly the health of his circulatory system. The easier it is to achieve erections, the healthier the man. By identifying and correcting the factors that might be undermining erections, a man not only can restore his sex life—he might save his life.

Here, five factors that can ruin a man’s sex life and what to do about them…

HEART DISEASE

An artery leads directly to the penis and subdivides into three more arteries, supplying the robust flow of blood on which an erection depends. If those arteries are narrowed or blocked, it’s likely that there’s a problem with all your arteries—including the arteries supplying blood to your heart.

Troubling recent finding: A decade-long study published in Journal of Sexual Medicine shows that men over age 50 with ED are 2.5 times more likely to develop heart disease, and men under age 50 are 58% more likely. And a study of men with ED who were already ­diagnosed with heart disease shows that they are twice as likely to have a heart attack and 90% more likely to die of heart disease, compared with men who have heart disease but not ED.

What to do: Eat a Mediterranean diet, emphasizing vegetables, fruits, whole grains, beans, fish and healthy fats (in olive oil, avocado and nuts). It’s a diet proven to prevent and treat heart disease—and several studies from Italy show that a Mediterranean diet also can prevent and cure ED.

Other conditions that increase the risk for ED: Type 2 diabetes, obesity, gout and sleep apnea—and studies show that these conditions also are helped with a Mediterranean diet.

Important: If you have ED, make an appointment with your doctor, tell him/her about your problem and ask for a complete workup to check for cardiovascular disease.

ALCOHOL

Alcohol is a central nervous system depressant, and despite what many people think, it dampens sexual arousal—and that’s particularly true for older men.

What to do: Limit yourself to no more than one to two drinks per day. (A drink is one 12-ounce beer, a five-ounce glass of wine or 1.5 ounces of 80-proof spirits.)

What not to do: Washing down fried foods with beer (or any alcohol) is a double whammy. Eating fried food immediately spikes the level of blood fats such as triglycerides, impeding blood flow to the penis for several hours.

MEDICATIONS

ED can be a side effect of taking one or more prescription medicines. The most common offenders are drugs to treat high blood pressure, heart ailments, depression and allergies. Telltale sign: You start a new medication, and you suddenly notice that you’re having erectile ­difficulties.

What to do: Talk to your doctor about using a different medication to treat your health problem. For example, one class of antidepressants (selective serotonin reuptake inhibitors, or SSRIs) often leads to libido issues and ejaculation problems contributing to ED, but the antidepressant bupropion (Wellbutrin) rarely does.

LACK OF EXERCISE

Regular exercise lowers your heart rate and blood pressure and helps clear life-threatening plaque from arteries—all of which translates into preventing or reversing ED.

Important new finding: A recent study in Journal of Sexual Medicine found that men who have risk factors for heart disease were 50% more likely to suffer from ED if they did not exercise regularly. Another study shows that exercise can improve ED even in men who are already taking a drug for ED.

What to do: Walk! It is a proven way to prevent and treat ED. When researchers from Duke University studied men with an average age of 62, they found that those who walked briskly for 30 minutes, four days a week, were 66% less likely to have ED.

STRESS

Too much stress can undermine erections by slowing the production of hormones (including testosterone, the master male hormone) and by impeding blood flow to the penis.

What to do: The best way to reduce stress is to spend at least 20 to 30 minutes a day doing something you personally enjoy—whether it’s watching your favorite comedian on Netflix, participating in a hobby such as woodworking or going for a walk with your dog.