There is nothing wrong with giving charity on behalf of all the Muslims, in sha Allaah.
In the answer to question no. 20996, it says that charity may benefit Muslims both living and dead, and we quoted a fatwa of Shaykh Ibn Baaz (may Allaah have mercy on him) concerning that.
Shaykh Ibn Jibreen was asked in Sharh ‘Umdat al-Ahkaam (lesson 38, p. 2): When some people give charity, they say: “It is a blessing and a gift to reach the soul of the Prophet Muhammad and the souls of all our dead.” What is the ruling on that?
The answer was:
There is no need to say this; the intention alone is sufficient, and it is better if he makes it for himself, or gives it on behalf of his own deceased loved ones, or on behalf of the deceased Muslims.
As for his saying “to the soul of the Prophet (peace and blessings of Allaah be upon him)”, I do not think this is right, because the Prophet (peace and blessings of Allaah be upon him) will have a reward equal to that of the good deeds of his ummah, even if they do not dedicate similar deeds to him, and the salaf did not dedicate any good deeds to the Prophet (peace and blessings of Allaah be upon him), because the one who guided the ummah and showed them the way will have a reward equal to that of their good deeds, because he said: “The one who calls to right guidance will have a reward equal to that of those who follow him.”
There is nothing wrong with giving charity on behalf of the Muslims or praying for them, whether they are relatives or not. There is nothing wrong with that, but saying these words is not proper. But if you say – for example – “O Allaah, give its reward to me and to my deceased loved ones, or to the Muslims”, there is nothing wrong with that. End quote.
Although that is permissible, the basic principle is that when it comes to virtuous deeds and drawing close to Allaah, the Muslim should focus on himself and not prefer others to himself with regard to the rewards. He is in the greatest need of Allaah’s forgiveness and mercy, and he does not know, perhaps a single hasanah (reward for good deed) will tip his balance on the Day of Resurrection and thus admit him to Paradise. Allaah has commanded us to protect ourselves from the Fire first, and then one’s family, as He says (interpretation of the meaning):
“O you who believe! Ward off yourselves and your families against a Fire (Hell) whose fuel is men and stones”
Shaykh al-Islam Ibn Taymyah was asked in Majmoo’ al-Fataawa (24/321) about a person who reads the Holy Qur’aan or part of it: is it better for him to dedicate the reward to his parents and the deceased Muslims? Or to keep the reward just for himself?
The best acts of worship are those which are in accordance with the teachings of the Messenger of Allaah (peace and blessings of Allaah be upon him) and the practice of the Sahaabah, as it is narrated in a saheeh report that the Prophet (peace and blessings of Allaah be upon him) used to say in his khutbahs: “The best of speech is the Word of Allaah, and the best guidance is the guidance of Muhammad; the worst of matters are those which are newly invented, and every innovation is misguidance.”
Ibn Mas’ood said: Whoever among you wants to follow a path, let him follow the path of one who has died, for the one who is alive is not safe from fitnah. Those are the companions of Muhammad.
Once this principle is understood, then the prevalent custom among the Muslims in the best generations was to worship Allaah by all kinds of prescribed acts of worship, both obligatory and supererogatory, prayer, fasting, reading Qur’aan and so on. They would pray for the believing men and women as enjoined by Allaah, and for the living and for the dead in the funeral prayers, and when visiting the graves and so on…
However, it was not the habit of the salaf when offering voluntary prayer, fasting, doing Hajj or reading Qur’aan to dedicate the reward for that to the deceased Muslims, or to their loved ones. Rather their habit was as described above. People should not turn away from the path of the salaf, for it is the best and most perfect. And Allaah knows best. End quote.
Based on this, you should strive hard to obey Allaah and worship Him, and say a lot of du’aa’s for the Muslims in general.
We ask Allaah to help you to do that which He loves and which pleases Him.
And Allaah knows best.