In Lee Smooth Manifolds, this problem is given:
if $S \subset M$ is smoothly embedded and every $f \in \mathcal{C}^{\infty}(S)$ extends to a smooth function on $\textit{all}$ of $M$, then $S$ is properly embedded.
Properly embedded means the inclusion $i: S \to M$ is proper. For this we have to show $S$ is closed or it's a level set of a continuous function.
I think it should be just a few lines, but I am totally stuck for two hour! Please to help, thanks =)
What I tried: Since $S$ is embedded, it can be covered with slice charts $U_p$. If $V = \cup U_p$ then with bump functions we can make $S$ closed in $V$ by making it a level set. But $V$ is open, so it does not mean $S$ is still closed in the whole manifold. I could not alter this into proof.
I also tried to make an extension of the identity map of $S$, so that then $S$ would be a retract and closed.
Best Answer
I would try to prove the contrapositive. Here's why.
The utility of smooth functions comes from the existence of bump functions. To extend any $f\in C^\infty(S)$ to a smooth function on $M$, all we need is an $\epsilon$ of wiggle room and we'll be able to extend $f$ to a function that is supported on a small neighborhood of $S$.
By contrast, if $f$ is embedded but not properly embedded, then that means exactly that there's a pathology somewhere: a compact set in $M$, pulling back to a non-compact set in $S$. This should intuitively correspond to a place where $S$ has no "wiggle room" in $M$.
So I would take that compact set $K$ in $M$, look at its pullback $\iota^{-1}(K)\subset S$, and then try to construct a function in $C^\infty(S)$ that is supported on $K$ and has no smooth extension to $M$. You should be able to use the pathology in $K\cap S$ to construct $f\in C^\infty(S)$ with not even a continuous extension to $M$.
Spoiler alert!