Contact form send to selected email from dropdown

I simply want the message from my contact form to be sent to whoever is chosen in the drop down selection on the form page. And if possible, is there a simple way to add spam prevention? Thank you!

HTML

[code]






— Send to —
person 1
person 2
person 3











[/code]

PHP
[php]<?php
$name = $_POST[“name”];
$to = $_POST[“to”];
$from = $_POST[“email”];
$message = $_POST[“message”];

$email_from = $email;
$subject = “New message from” . $from;

mail($to,$subject,$message,$from);

echo ‘

Your message has been sent.

’;
?>[/php]

I would also like the email to be formatted like the following:

Subject: New Message from $name

Name: John Doe
Email: [email protected]
Message: I like your website.

To stop spam bots you can look into implementing reCaptcha.

I am not sure where the $to and $email variables come from. The value of the Send To drop down should be an email address or at least a value that you can use in your PHP to select an email address. (You may not want to put email addresses in your HTML code). The from variable should be something like [email protected].

Also make sure that the mail configuration is correct in your php.ini file.

Sponsor our Newsletter | Privacy Policy | Terms of Service