You need to use either AJAX or sockets. If you don't want to bother with sockets, use long polling. Scheme:
- A request is sent to the server.
- The connection is not closed by the server until a message appears.
- When the message appeared – the server responds to the request, mailing.
- The browser then makes a new request.
Works well via AJAX. For more details, see here