There are about four ways that people can leave your web site. So the place to start is to consider those events and detect what you can.
One way that they can leave your site is to click a link on your site that goes to some other web site. Say for example that you link to google. You could pass them to an intermediary page first, say your goodbyes, and then move them on to google. For example, you could make your link to www.mysite.com/out.php?d=google.com
Another way that they could leave your web site is to type their own URL into the location bar. Body unload will detect that the user is leaving the page itself but cannot detect whether they are leaving the web site. It would be a security and privacy risk if website X could determine that their users are typing website Y into the location bar. It's none of your business that I go to your site and then jump over to playboy.com for awhile. So no, you can't know whether or not I'm leaving the page to go some other web site.
Another way that they could leave your web site is to click one of their bookmarks. Same as typing a URL into the location bar, you can tell that I'm leaving the page but you have no idea whether it's to leave your site or not.
Lastly, they could shut down their web browser, start it back up, and go to another web site. In this instance, the web browser is shut down so you can't detect anything. So no, you can't tell when I'm leaving the page to visit another web site.
Now here's what you can do: You can have them log in and cookie them. Get their email address. Put something in your header.php file that writes the current time and their userid to the tracking database. You can write a cron job that checks that table every 10 minutes to see if there are any users who were on a page and never loaded another page in the last 40 minutes. If they haven't loaded a new page in 40 minutes, it's a pretty safe bet that they've left your site. So even if you're wrong about some people (maybe really slow readers), you'll be right about 98% of the time. You can send them an email that says, "Sorry you left the site. Hope we can be of service. Etc Etc."
So from a technical perspective, that's how you can do it. Not very reliable EXCEPT when you are providing them with the link to leave your web site.
Now comes the practical perspective. Can you imagine if you visited a store at the mall and the clerks followed you out into the hall as you tried to leave the store? I mean, you're leaving the store because you don't want to be there anymore. It's not that you hate the store, it's just that you don't want to be there. When the clerks come out of the store and say, "Did we do something wrong?", "Didn't you find what you were looking for?", "Hope to see you again.", that makes me never want to go to that store again. And it makes me want to tell my friends about the bad experience there.
So the summary is: If the user is leaving your site because you are linking them to that other site, then you have good reason to say one last thing to them and you can easily use the intermediary web page technique. If they are leaving your site because they don't want to be here anymore, then you have little reason to say anything else to them and there's not much way to detect that they are leaving.