Matthew 5:16 (also 1 Peter 2:12)
"In the same way, let your light shine before men, that they may see your good deeds and praise your Father in heaven."
"Be careful not to do your 'acts of righteousness' before men, to be seen by them. If you do, you will have no reward from your Father in heaven.
"So when you give to the needy, do not announce it with trumpets, as the hypocrites do in the synagogues and on the streets, to be honored by men. I tell you the truth, they have received their reward in full. But when you give to the needy, do not let your left hand know what your right hand is doing, so that your giving may be in secret. Then your Father, who sees what is done in secret, will reward you."
Matthew 5:16 refers to Christians living in the secular world (as opposed to avoiding it). A Christian who lives honorably out of a genuine desire to please God, and who genuinely loves others, will be noticed by others and will serve as a testimony to God. Conversely, a Christian whose sole motivation in doing good is to be noticed and praised by people will sooner or later be recognized as a hypocrite, and will turn people away from God.
The resolution of these two teachings is best illustrated by example. Suppose Max volunteers at a homeless shelter once a week. If Max goes quietly each week and never mentions it to anyone, his service will still be noticed by the people he serves and those he serves with, and likely will eventually be noticed by others who know him - someone may see him entering or leaving the homeless shelter, or talk to someone else who works there. If Max's sole motive is to make people think he's righteous, and he loudly announces to everyone that he's helping the homeless, people will be turned off by his boasting, and his actual service may be of lesser quality (since he lacks true motivation to do it).
Or take the original example of giving to the poor. Suppose Doris regularly donates a significant portion of her salary to the needy. If Doris gives quietly - anonymously when possible, never mentioning it to anyone - those who know her may still realize what she's doing. Her immediate family will likely know of her spending habits. Her extended family and friends may observe that she lives frugally and that she's a kind and generous person and put two and two together. Or one of her friends, having fallen on rough times, may be the recipient of her generosity.
In short, Jesus' teaching is that we are to do good works, but quietly, without seeking recognition. God is able to use our works and make them known to others when it is beneficial to do so; we don't need to do any advertising ourselves.
Other responses (offsite)