From early in Shakespeare's Hamlet, Ophelia's brother, Laertes, and her father, Polonius, express concern to Ophelia about her relationship with Hamlet. The first time Ophelia appears in the play, Laertes advises Ophelia that Hamlet's apparent interest in her is simply a passing infatuation, "forward, not lasting, / The perfume and suppliance of a minute; / No more" (1.3.9–11). Laertes warns Ophelia against losing her heart and her chastity, "her chaste treasure" (1.3.34), to Hamlet.
The audience learns, however, as does Laertes, that Ophelia isn't nearly as innocent and naive as Laertes believes she is when Ophelia turns Laertes's advice back on him.
OPHELIA. But, good my brother,
Do not, as some ungracious pastors do,
Show me the steep and thorny way to heaven,
Whilst, like a puff'd and reckless libertine,
Himself the primrose path of dalliance treads
And recks not his own rede (1.3.49–54).
A little later in the same scene, Polonius appears to be well aware that Ophelia's relationship with Hamlet is more serious, and more intimate, than Laertes thinks it is.
POLONIUS. 'Tis told me, he hath very oft of late
Given private time to you, and you yourself
Have of your audience been most free and bounteous (1.3.97–99).
Polonius cautions Ophelia against getting too deeply involved with Hamlet, "From this time / Be something scanter of your maiden presence" (1.3.127–128), and he advises her not to believe everything he says to her. Ophelia plays the dutiful sister and daughter and agrees to heed Laertes and Polonius's advice.
In act 1, scene 5, after Hamlet sees his father's ghost, Hamlet decides "to put an antic disposition on" (1.5.192)—in other words, to act crazy. The first person on whom Hamlet tries out his "antic disposition" act is Ophelia. Ophelia goes running straight to Polonius to report Hamlet's seemingly horrifying behavior towards her (2.185–112).
The question arises as to whether Ophelia was truly taken aback by Hamlet's behavior or if Hamlet let Ophelia in on his "antic disposition" secret and sends her to Polonius with her horrifying story, which Hamlet knew Polonius would take directly to Claudius as Hamlet intended—and which Polonius does.
Hamlet and Ophelia's first scene together, in act 3, scene 1, takes place in front of the eavesdropping Polonius and Claudius. Is this just another act that Hamlet is putting on for Polonius and Claudius, with Ophelia as his willing accomplice? Hamlet knows that Polonius and Claudius are listening in on his conversation with Ophelia. Why else would he ask Ophelia, out of the blue, where Polonius is?
Or is Ophelia truly upset by the ferocity of Hamlet's denials of his love for her and his harsh treatment of her that it starts her down the path to madness? Ophelia's light, witty, teasing banter with Hamlet during the "play-within-a-play" in act 3, scene 2 would seem to indicate otherwise, but Ophelia might be hiding some underlying distress.
All in all, Ophelia and Hamlet have a much deeper relationship than anyone realizes, and their relationship will have a much greater effect on both of them and the people around them than anyone, including Hamlet and Ophelia, anticipates.
Two significant things happen between act 3, scene 2 and the next time Ophelia appears in the play in act 4, scene 5. Hamlet accidentally kills Polonius, and Claudius sends Hamlet to England, where, unbeknownst to Hamlet, Claudius intends to have Hamlet executed.
There's no scene in which Ophelia is told about her father's death where the audience can see her reaction, there are no more scenes between Hamlet and Ophelia, and there's no scene in which Ophelia is told about Hamlet being sent to England. Ophelia is suddenly deprived of her father and her lover. Polonius is truly dead to her, Hamlet is symbolically dead to her, and she's left entirely on her own to reconcile her feelings towards each of them.
The next time the audience sees Ophelia, in act 4, scene 5, Ophelia makes reference in dialogue and in songs to both of these events, as well as to Hamlet and Polonius.
Ophelia first refers to Hamlet, "How should I my true love know" (4.5.26), and then she appears to refer to Polonius, "He is dead and gone, lady" (4.5.32). She might be referring to Hamlet, possibly believing or imagining that he's dead, because she again seems to refer to her relationship with Hamlet with a somewhat bawdy song, "Tomorrow is Saint Valentine's day" (4.5.54), that implies intimate relations between them.
It might be that Ophelia is upset by her father's death at the hand of the man she loves, and she's torn between her feelings for Hamlet and Polonius. She's likely also upset by Hamlet's sudden departure to England without even a word of goodbye between them, and all of these conflicting feelings are slowly leading Ophelia towards madness.
When Ophelia returns to the scene, she sings what appears to be a song that relates to Polonius, "They bore him barefac'd on the bier" (4.5.180), but the song ends with the words, "Fare you well, my dove" (4.5.183), which seem more appropriately sung about Hamlet than about Polonius.
Ophelia distributes flowers to Claudius, Gertrude, Laertes, and herself, each of which kind of flower has a symbolic meaning, and she remarks, "I would give you some violets, but they wither'd all when my father died" (4.5.197-198), which is a direct reference to Polonius. Ophelia then sings a song that includes words which appear to be directly related to Polonius—"His beard was white as snow" (4.5.209)—after which she exits the scene, and she doesn't appear alive again in the rest of the play.