Suppose $R$ is a commutative ring, $I$ is an ideal of $R$, and $M$ a finitely generated $R$-module. (Usually in this problem $R$ includes $1_R$.) Let $\phi : M \to M$ be an $R$-homomorphism, and $\phi(M) \subseteq IM$. How to prove that $$\exists a_1 ,...,a_n \in I \text{ so that } \phi^n+a_1\phi^{n-1}+\cdots+a_n 1_M=0\ ?$$
I tried to solve this using the definition:
$M$ is a $R$-module and includes a finite generator, i.e : $RX=M$, $X=\{x_1,...,x_n\}$,
and I know that $IM, \phi(M)$ are sub-modules of $M$.
$IM=IRX=IX$ because $I$ is an ideal in $R$.
$$\phi(x_i)= \sum_{j=1}^n a_{ij}x_j, a_{ij}\in I, x_i\in M$$
You've noted that $$ \phi(x_i)= \sum_{j=1}^n a_{ij}x_j, a_{ij}\in I, x_i\in M $$ which can be rearranged as $$ \sum_j (\delta_{ij}\phi-a_{ij})x_j=0. $$ Let $A=(a_{ij})$, and $X=(x_1,\dots,x_n)^T$. This implies that $(I\phi-A)X=0$, since the $i$th entry of the resulting vector is just the above sum. Left multiplying by the adjugate of $I\phi-A$, we have $$ \operatorname{adj}(I\phi-A)(I\phi-A)X=\det(I\phi-A)IX=0 $$ so that $\det(I\phi-A)x_j=0$ for all $j$, and thus $\det(I\phi-A)$ is the zero endomorphism. Expanding the determinant gives the desired equation.
This is essentially Proposition 2.4 in Atiyah and MacDonald.