Linear codes with few weights have applications in secret sharing, authentication codes, association schemes, data storage systems, strongly regular graphs and some other fields. Two-weight linear codes are particularly interesting since they are closely related to finite geometry, combinatorial designs, graph theory. In this paper, we present a new approach to constructing linear codes with two or three weights from -polynomials and study their weight distributions. As an application of two-weight linear codes, we obtain three families of strongly regular graphs. Some of the presented strongly regular graphs are new.