This is kind of a tough question. As a faculty member, I get tons and tons of these emails and frankly ignore most of them. I feel kind of bad about it, but the main problem is that these emails usually don't give me any (positive) information that isn't already available from the Ph.D. application. If I'm on the committee that year, I'll probably see the application. And if not, well, either someone will bring it to my attention and ask me to have a quick look at the folder or not, but an email isn't going to change that.
I can at least tell you what not to do. Don't write more than 2-3 short paragraphs. Don't use more than 70 characters per line. Don't include attachments. Don't tell me how much you want to work with me. Don't tell me how hard you work. Don't brag about how great you are. Don't prostrate yourself before me ("Respected professor, it would be the highest honor to work with such a great scientific mind..."). Don't try to impress me. Don't use a script to try to make a mass email look like I'm the only professor receiving it (believe me, it's obvious the content wasn't written just for me).
Do include a link to your home page, especially if it contains papers and software. Do try to engage me about something other than the admissions process, but this is tricky because if it's just a transparent effort to try to improve your admissions prospects, I'll get annoyed, and if it's a dumb question about one of my papers, well then I might not be impressed.
Frankly, the thing that works the best is when it's not the candidate but somebody whose judgment I trust who emails me and suggests that I look out for the person. I don't like this because A) it tends to favor people in the US, and B) I have this feeling that I'm missing out on loads of talent for the simple reason that it's much harder to identify and evaluate good people who aren't compared to people I already know. (I will say is that if I'm on the admissions committee, you are in my area, and you have a great statement of purpose, I will read whichever publication you make sound the most interesting. That's a big time investment, but it has definitely paid off for me as I've found some great students that way. I could go on about the admissions process, but that's not your question.)
I guess basically the more genuine contact I or my group has had with someone not about admissions, the easier it will be to realize that I might have good chemistry with the student and read the papers. In one recent case, one of my Ph.D. students had previously interacted with a candidate and told me that the guy was a great hacker. I looked at the application and quickly put the candidate at the very top of my list.
Obviously what I wrote is just one professor's perspective, and faculty members are all different. As the OP points out, some faculty actively want potential Ph.D. students to contact them and advertise that on their web pages. And maybe for more junior faculty, or schools below the top 10, or people who just have better email habits than I do, email is a useful recruiting tool.