For eight hundred years prior to the establishment of Valentine's Day, the Romans had practiced a pagan celebration in mid-February commemorating young men's rite of passage to the god Lupercus. The celebration featured a lottery in which young men would draw the names of teenage girls from a box. The girl assigned to each young man in that manner would be his sexual companion during the remaining year.
In an effort to do away with the pagan festival, Pope Gelasius ordered a slight change in the lottery. Instead of the names of young women, the box would contain the names of saints. Both men and women were allowed to draw from the box, and the game was to emulate the ways of the saint they drew during the rest of the year.
Instead of the pagan god Lupercus, the Church looked for a suitable patron saint of love to take his place. They found an appropriate choice in Valentine, who, in AD 270 had been beheaded by Emperor Claudius.
Claudius had determined that married men made poor soldiers. So he banned marriage from his empire. But Valentine would secretly marry young men that came to him. When Claudius found out about Valentine, he first tried to convert him to paganism. But Valentine reversed the strategy, trying instead to convert Claudius. When he failed, he was stoned and beheaded.
During the days that Valentine was imprisoned, he became acquainted with the blind daughter of his jailer. Among several stories regarding their relationship, he healed her from her blindness before his death. Before he was taken to his death, he signed a farewell message to her, "From your Valentine." The phrase has been used ever since.
Although the lottery for women had been banned by the church, the mid-February holiday in commemoration of St. Valentine was still used by Roman men to seek the affection of women. It became a tradition for the men to give the ones they admired handwritten messages of affection, containing Valentine's name.