Let $K:=\operatorname{Ker}(f)$ and $I:=\operatorname{Im}(f)$.
$f^2=0$ is equivalent to $I\subseteq K$.
So you first pick a subspace $K$ of $E$ and then pick a subspace $I$ of $K$. The sets of functions you'll attain for different $K$ and $I$ are clearly disjoint so if you manage to count for each $I$ and $K$, you'll then just have to sum over all $I$ and $K$.
Now, suppose $I$ and $K$ fixed. Take some $H$ so that $E=H\oplus K$. Then it is equivalent to give the action of some $f$ on $E$ or to give it on both $H$ and $K$. Since the action on $K$ is trivial, giving the action of $f$ on $E$ is equivalent to giving its action on $H$, i.e. a function $H\to I$ that has image $I$. Since those functions are surjective and both spaces are or equal dimension, those functions will all be automorphisms. Now take $\varphi$ any (fixed) automorphism between $I$ and $H$. The application $( g : H \to I)\mapsto (\varphi \circ g : H \to H)$ is a bijection. So to count the morphisms when $I$ and $K$ are fixed, you just have to count automorphisms of $I$.