Hello,

Yes, it is possible.

Please read this article that provides very useful information for your case:

Getting Married In Spain: General Overview and Legal Issues For Foreigners In...