For a complex square matrix $M$, let us say $n\times n$, we can define the $\mathbb{C}$-algebra homomorphism,
$$ \phi_M:\mathbb{C}[x]\rightarrow Y_M:=\{N\in\mathbb{M}_n(\mathbb{C})|[M,N]=0\}$$ $$p(x)\mapsto p(M)$$
I would like to know when it is surjective (onto $Y_M$), I already know that for a diagonalizable matrix $M$ it is the case iff $M$ has distinct eigenvalues, but for the case where $M$ has a nilpotent part I do not know any conditions.