The lines that you mention are indeed from a play by William Shakespeare. To be specific, they are from the play "Two Gentlemen of Verona." They are spoken by the character Valentine. The lines are spoken in Act III, Scene 1.
The context is that the Duke has just found a letter in Valentine's cloak. The letter shows that Valentine intends to elope with the Duke's daughter Silvia (as it is spelled in the play). The Duke tells Valentine to leave his court. Valentine is sad at the idea of being separated from Silvia and he speaks the lines you mention.