What are the best practices for handling form submissions in PHP to avoid errors related to passing special characters like spaces in URLs?

When handling form submissions in PHP, it is important to properly sanitize and validate user input to avoid errors related to passing special characters like spaces in URLs. One common practice is to use the `urlencode()` function to encode special characters before passing them in URLs. This ensures that the data is properly formatted and prevents errors.

// Sanitize and encode user input before passing it in URLs
$name = urlencode($_POST['name']);
$email = urlencode($_POST['email']);

// Use the sanitized and encoded data in your URL
$url = "http://example.com/process.php?name=$name&email=$email";

// Redirect to the URL
header("Location: $url");
exit();