How does this happen? Usually, when you are faced with a tall building, in order to capture the full height, the natural tendency is to tilt your camera upwards to capture the top of the building. And in particular, this effect is common when you are using a wide angle lens. That is, the top of the building looks small while the base of the building looks big.
However, this distortion may not be a bad thing if you use it correctly. What you can do is, to exaggerate the effect by having more distortion. You can do this by going close to the building and point the camera upwards. But on the other hand, if you have only a slight distortion, it may give you worse effect.
Let us come back to the point to have straight standing building shot. The first step is to move away from the building and followed by having your camera straight. However, this option may not be away possible as there is a limit to the distant you can move backward. Nevertheless, try using this technique first.
Secondly, you can use a software called Elements 5 to correct this. However, this can only correct slight distortion. If your photo has verticals that are distorted too much, the software cannot do much.
The third option is to use a special shift lens. But this is an expensive option. This specialized lens uses a mechanism to shift the position of the lens independent of the camera. This allows you to keep the camera vertical but still include much more of the top of the building.
Above are three suggested techniques you can use when taking building photography to keep them straight. Explore them and see the effect yourself.