Look at your code closely, there is a glaring error:
$firstname = mysql_real_escape_string($_POST['youremail']);
$lastname = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['receiveremail']);
$datepicker = mysql_real_escape_string($_POST['message']);
$query="INSERT INTO $tablename (rand, youremail, name, receiveremail, message)
VALUES ('".$rand."', '".$youremail."', '".$name."', '".$receiveremail."', '".$message."')";
In your query you are trying to insert the values for variables $youremail, $name, $receiveremail, $message - yet nowhere in your script do you have these variables declared and assigned values. What you do have are the variables $firstname, $lastname, $email, $datepicker (which don't make any sense in themselves as they don't relate to the posted data) and therefor it should be those variables that you use in your query.
The $rand number is being inserted as you declare it and assign a value early on in your script.