It would have been good of you to provide us with details about the said relations and the marriage so that you might not need to study the different rules concerning the circumstances that can be similar to your situation. In any case, we will give an answer to your question as under:
If you did not have any sexual intercourse with your husband after your marriage in 1997 and you got a divorce from him in 2003, such a divorce is technically called "Talaq Bāyin"  or irrevocable divorce. In the case of an irr evocable divorce a man cannot rejoin his wife without reciting the formula of marriage contract again.  Therefore, if your husband had sexual intercourse with you in 2003 after the divorce, both of you have committed an illicit (haram) act. In case you thought that a husband and wife can live together without Nikah (marriage contract) and with this assumption you had sex, the sexual intercourse is considered to be Waty bish-shubhah (intercourse by mistake). 
In case you had sex with your husband in the year 1997 and then you got a divorce from him in 2003, if the divorce had been a Khula  divorce, again it had not permissible for you to live with her without marriage contract except for when you may have taken back, during Iddah (waiting period), what you had surrendered to him. In case, your divorce was neither of the first type (divorce without sexual intercourse) nor of the second type (Khula divorce) and you had sex in the year 1997 and then you lived together with each other a few days after the divorce in 2003, your intimate relation with him in the said manner is in order.
You have said that "after two months, they again separated from each other", obviously separation should not be without divorce. In fact, divorce should be carried out and conducted again in the same way as it was carried out in the year 2003. Hence, if you have separated from each other through divorce and then you married the second man in the year 2006, the marriage is valid.
1. Question 3181 (site: 3427) (The right of divorce for woman if her husband does not have sexual intercourse with her)
5849 (site: 6059)
(What are the rules and conditions of Khula divorce?)
 - See: question 2952 (site:
 - Tawzih al-Masail (with annotations by Imam Khomeini) vol.2, pg. 529.
 - Waty bish-Shubha means that a man believes that a woman is his wife, although she is not his wife in reality, and he has sex with her with this assumption she is his wife. See: Gulpaigani, Muhammad Reza, Hedayatul 'Ebad, vol.2, pg. 409.
 - A woman who develops an aversion from husband and is not willing to live with him and there is fear that the continuation of their marriage life would lead to committing sin, can surrender to him her dower or other property so that her husband may divorce her. This divorce is called ‘Khula’ divorce’.