Primary and secondary alcohols can be converted to haloalkanes with reagents such as: phosphorus tribromide, phosphorus trichloride, thionyl chloride, and phosphorus pentachloride.

preparacion-haloalcanos-a-partir-alcoholes
 
The mechanism of these reactions is of the SN2 type and only primary and secondary alcohols react. Let's look at the mechanism of the first reaction.
 
preparacion-haloalcanos-a-partir-alcoholes
 
Stage 1 . Alcohol attack on phosphorus tribromide
 
preparacion-haloalcanos-a-partir-alcoholes
 
Stage 2. Bimolecular nucleophilic substitution, with bromide acting as nucleophile
 
preparacion-haloalcanos-a-partir-alcoholes
 
All the bromines of PBr3 are reactive and the mechanism is repeated two more times.