This is the code I am using before the header command:
if ($name && $email && $username && $password) { // If everything's okay.
// Register the user.
// Send an email.
$body = "Thank you for registering with our site!\nYour username is '{$_POST['username']}' and your password is '{$_POST['password1']}'.\n\nSincerely,\nUs";
mail ($_POST['email'], 'Thank you for registering!', $body, 'From: [email]admin@site.com[/email]');
header ('Location: thankyou.php');
exit();
} else {
$message .= '<p>Please try again.</p>';