Mystery Gift, a function in the games since Gold/Silver makes a welcome return in Diamond & Pearl. Its uses however are limited and almost all require you to be at a Nintendo-held event:

First, to activate the Mystery Gift function, go to the Jubilife TV Center..on the second floor, there is a man who accepts sayings from you. Tell him the following; "EVERYONE HAPPY" & "WI-FI CONNECTION" and he shall say he can pull some strings and get your Mystery Gift. Save your game and reset

Mystery Gift MenuOn the main menu now will be the Mystery Gift feature. Mystery Gift has several options for you to utilise; "Get From A Friend", "Get Via Wireless" & "Get Via Nintendo Wi-Fi Connection"

Get From Friend

In some circumstances, you will obtain a Mystery Gift from an event that you will be able to share with a friend through the Wonder Card which you will have stored on your game providing you haven't picked up the gift from the PokéMart

Get Via Wireless

This function is likely to be the more common function that you will use. When at a Nintendo Event, such as the upcoming Darkrai Event in Japan, if you use the Get from Wireless Function, you will be sent a Wonder Card that contains the Darkrai, or in the case of the other events that are likely to happen over time
This function is also used with the Wii Game Pokémon Battle Revolution. During your completion of the game, you will accumulate many PokéCoupons that you can purchase items with. These are then sent through the Wii's Wireless functions to your DS by having you access this Mystery Gift function.

Battle Revolution Wireless Connection
This is also they way that the special Pikachu, Electivire & Magmortar are sent from Battle Revolution

Mystery Gift WiFiGet Via Nintendo Wi-Fi Connection

Possibly the most intriguing option is the ability to get a Mystery Gift from the Nintendo Wi-Fi Connection. It is currently unknown if Nintendo will fully utilise this feature for the distribution of rare Pokémon and items later on in the game's life. Currently, however, there is nothing there. You need to wait for Nintendo to host an online-event stating when to connect and for what for it to reap any benefits

Hopefully this article has alleviated much confusion about the Mystery Gift and how to utilise it, essentially there being no way to do it until Nintendo holds an event, you cannot just do it between friends as was possible with Gold, Silver & Crystal.