In what ways can PHP be used to handle contact form submissions where only the recipient's name is provided, without revealing their email address?
When handling contact form submissions where only the recipient's name is provided, without revealing their email address, you can use a lookup table or array in your PHP code to map the recipient's name to their email address. This way, the email address remains hidden from the user submitting the form.
// Lookup table mapping recipient names to email addresses
$recipientEmails = [
"Recipient Name 1" => "recipient1@example.com",
"Recipient Name 2" => "recipient2@example.com",
// Add more recipients as needed
];
// Get the recipient's name from the form submission
$recipientName = $_POST['recipient_name'];
// Check if the recipient's name exists in the lookup table
if (array_key_exists($recipientName, $recipientEmails)) {
$recipientEmail = $recipientEmails[$recipientName];
// Send the email to the recipient's email address
// Your email sending code here
} else {
// Handle the case where the recipient's name is not found
echo "Recipient not found.";
}