How can dropdown menus be implemented in PHP forms to select recipients for emails?
To implement dropdown menus in PHP forms to select recipients for emails, you can create a dropdown menu in the HTML form and populate it with options from a database or a predefined list. When the form is submitted, you can retrieve the selected recipient from the dropdown menu and use it to send the email.
<form method="post" action="send_email.php">
<label for="recipient">Select recipient:</label>
<select name="recipient" id="recipient">
<option value="recipient1@example.com">Recipient 1</option>
<option value="recipient2@example.com">Recipient 2</option>
<option value="recipient3@example.com">Recipient 3</option>
</select>
<input type="submit" value="Send Email">
</form>
```
In the `send_email.php` file, you can retrieve the selected recipient from the form submission and use it to send the email:
```php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$recipient = $_POST["recipient"];
// Code to send email to the selected recipient
// For example:
$subject = "Test Email";
$message = "This is a test email.";
mail($recipient, $subject, $message);
echo "Email sent to " . $recipient;
}
?>
Keywords
Related Questions
- How can PHP scripts differentiate between manually entered and automatically filled inputs on a webpage?
- How can arrays be effectively utilized in PHP to store and display navigation data retrieved from a database?
- What are some alternative methods or functions in PHP that can be used to check for the absence of a specific string within content, besides strpos?