Shulchan Arukh, Yoreh De'ah Siman 285
Can copy this into an AI, or connect the whole library to your assistant. For deeper learning, you can directly use the original seforim, sites, and apps.
מצות עשה לכתוב פ' שמע והיה אם שמוע ולקבעם על מזוזת הפתח וצריך ליזהר בה מאד וכל הזהיר בה יאריכו ימיו וימי בניו ואם אינו זהיר בה יתקצרו: הגה ומ"מ אם אין ידו משגת לקנות תפילין ומזוזה יקנה תפילין ולא מזוזה (ירושלמי סוף מגילה ובא"ח סי' ל"ח סי"ב) דמצוה שהיא חובת הגוף עדיפא:
It is a positive commandment to write the Shema, the Veyhaya Im-Shamoa, and to fix them on the side of one’s door, and one needs to be very careful in this, and all who are careful in this, their days will be lengthened, and the days of their children. And if one is not careful in this, his days will be shortened. Rama: And in any case, if it's out of his reach to acquir Tefillin and a Mezuzah, let him acquire Tefillin and not Mezuzah (Yerushalmi Megillah, end; O"C 38:12), as a mitzvah that is a bodily obligation is greater.
נתינתה בטפח החיצון: הגה י"א כשאדם יוצא מן הבית יניח ידו על המזוזה (מהרי"ל שם ומוכח בעבודת כוכבים דף י"א) ויאמר ה' ישמר צאתי וגו' (במדרש) וכן כשיכנס אדם לבית יניח ידו על המזוזה:
Its placement is in the outer tefah. Rama: There are those who say that when a person leaves his house, he puts his hand on the Mezuzah there and says “God will guard my going, etc.” And so too when one enters a house, one puts his hand on the Mezuzah.