The linear and nonlinear optical (NLO) properties of 3,5-dinitrobenzoic acid and some benzamide derivatives are determined using density functional theory. The B3LYP levels with a [Formula: see text] basis are used to geometrically optimize 3,5-dinitrobenzoic acid with benzamide derivatives (DBBZM, DB1BZM, DB2BZM, DB3BZM, and DB4BZM). The low energy gap value indicates the possibility of intramolecular charge transfer. These calculations clearly show that the studied molecules can be used as attractive future NLO materials. Their first-order hyperpolarizability is found to be in the [[Formula: see text], [Formula: see text] esu] range, indicating that they have significant NLO properties. Furthermore, the RDG, AIM, NBO analyses, the MEP, and gap energy are calculated. The presence of intermoleculars O–H[Formula: see text]O and N–H[Formula: see text]O is confirmed by a topological feature at the bond critical point, determined by AIM theory and NBO analyses. All of these calculations have been performed in gas phase as well as cyclohexane, toluene, and water solvents in order to demonstrate solvent effect on molecular structure and NLO properties. In a final step, a molecular docking study was performed to understand the structure–activity relationship.