The problem requires us to find the number of mappings from domain to co-domain, where domain contains n elements and the co-domain contains 5 elements and the range should contain exactly 4 elements belonging to the co-domain. To find the number of functions, first, select the 4 elements out of those 5 elements. Hence the first factor is $\ \binom{5}{4} $.
Then, we have to place numbers 1 to n in these 4 "boxes" such that each box contains at least 1 element. Also, the order in which we place 2 numbers in the "box" doesn't matter. In the sense, the order of elements in a "box" doesn't matter.
Hence, placing the n elements in a line and making a total of 4 partitions, is over-counting, since we are counting the order in which elements are placed. To remove the multiple-count, divide the factorial of the number of elements in each partition. For example, let n=8. Suppose 1st "box" contains 3 elements, 2nd contains 2 elements, 3rd contains 1 element and 4th contains 2 elements. Then the total number of mappings will be $\ \frac{8!}{3!2!1!2!} $. But this is only the number of mappings where 1st "box" and other boxes contain a given number of elements. Hence, for general, the answer is $$\ \sum { \frac { n! }{ p!q!r!s! } } $$ and $$\ p+q+r+s=n,\quad p,q,r,s\in \mathbb{N} $$
To find the answer in a closed form, consider the expression $$\ n!{ \left( \frac { x }{ 1! } +\frac { { x }^{ 2 } }{ 2! } +\frac { { x }^{ 3 } }{ 3! } +.... \right) }^{ 4 } $$
The co-efficient of $\ {x}^{n} $ would be the sum of elements whose general term is $\ { \frac { n! }{ p!q!r!s! } } $, where $\ p+q+r+s=n,\quad p,q,r,s\in \mathbb{N} $ which is the required answer to the given question.
$$\ n!{ \left( \frac { x }{ 1! } +\frac { { x }^{ 2 } }{ 2! } +\frac { { x }^{ 3 } }{ 3! } +.... \right) }^{ 4 }=n!{ \left( 1+\frac { x }{ 1! } +\frac { { x }^{ 2 } }{ 2! } +\frac { { x }^{ 3 } }{ 3! } +....-1 \right) }^{ 4 }=n!{ \left( { e }^{ x }-1 \right) }^{ 4 }$$
Now, the problem will be solved for general $\ r $ which can be equated to 4 for the above problem.
$$\ n!{ \left( { e }^{ x }-1 \right) }^{ r }=n!\left( { e }^{ rx }-\binom{r}{1}{ e }^{ (r-1)x }+\binom{r}{2}{ e }^{ (r-2)x }+... \right) $$
The answer to the above question would be the co-efficient of $\ {x}^{n}$ in the above expression. Thus the answer is
$$\ n!\left( \frac { { r }^{ n } }{ n! } -\binom{ r }{ 1 }\frac { { (r-1) }^{ n } }{ n! } +\binom{ r }{ 2 }\frac { { (r-2) }^{ n } }{ n! } +... \right) ={ (r) }^{ n }-\binom{ r }{ 1 }{ (r-1) }^{ n }+\binom{ r }{ 2 }{ (r-2) }^{ n }+...=\sum _{ k=0 }^{ r }{ {\binom{r}{k} ({-1})^{k}(r-k) }^{ n } } $$
The same can be got by principle of inclusion and exclusion easily, but I thought this would be a rather "new" method. Hope it helps!
EDIT: For this problem, put r=4 in the above formula and then multiply by $\ \binom{5}{4} $