Yes, you can use 2" × 8" lumber as a door header, but you have to build up a 4" × 8" beam by gluing together two pieces of it on their wider side with a half-inch spacer between them.
A 2-inch piece of lumber has an actual thickness of 1.5 inches. Therefore, twice its thickness plus half an inch results in 1.5" × 2 + 0.5" =3.5", the actual thickness of a typical door header. Read more