@Lu***
You do NOT need to leave the country.
In Chiang Mai you need 21 days left on your current stamp to apply for an in country Non-O visa based on marriage. You would need to go make an appointment at the immigration office, meet the financial requirements and provide the appropriate documentation BUT you can most definitely get a 90 day Non-Immigrant Type O visa based on marriage at the immigration office up there.
Once you get that and you have 45 days left on the 90 day stamp they gave you you then apply for a yearly extension of stay, again by meeting the requirements.
The Non-O 90 day visa costs 2000baht, the year extension costs 1900baht.