PHP Contact Form with selectable recepient

Good Morning

I have 'googled' in vain to find a suitable tutorial to help create a php contact form with a user selectable recepient. Basicaly I would like to use the same simple (Name, Email, Enquiry) contact form, but send it to one of three email addresses based on a selection made by the user completing the form. For example if Sales is select then it will be emailed to sales@, Servicing will be emailed to servicing@ or Training emailed to training@

My php knowledage is limited - so is my coding but I can normal follow a good tutorial.

Thanks
WashcareAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Very simple sample
HTML
<form action="send.php" method="post">
 <label for="name">Name</label><input type="text" id="name" name="fullname" /><br>
 <label for="email">Email</label><input type="text" id="email" name="email" /><br>
 <label for="sendto">Send To</label><select  id="sendto" name="sendto">
<option>Please select one</option>
<option value="sales">Sales</option>
<option value="training">Training</option>
<option value="service">Service</option>
</select>
<input type="submit" >
</form>

Open in new window

PHP Code
<?php
// CHECK FOR VALID INPUT HERE
$fullname = isset($_POST['fullname']) ? $_POST['fullname'] : false;
$email = isset($_POST['email']) ? $_POST['email'] : false;
$sendto = isset($_POST['sendto']) ? $_POST['sendto'] : false;

// SETUP YOUR MAIL ADDRESSES HERE
// KEY IS THE VALUE THAT IS SENT FROM THE FORM
// VALUE IS THE EMAIL
$address = array(
   'sales' => 'sales@somewhere.com',
   'training' => 'training@somewhere.com',
   'service' => 'service@somewhere.com'
);

// POTENTIALLY MORE SANITISING / VALIDATION REQUIRED 
// CHECK WE HAVE EVERYTHING WE NEED
if ($fullname && $email && $sendto && isset($address[$sendto])) {
   // at this point we would probably use a library like PHPMailer to send the email
   // this demo uses PHP send - which is not advised - but without know more about
   // the use case difficult to advise on how to send email.

   mail($address[$sendto], "Subject", "Message goes here");
}

Open in new window


More on PHPMailer here
3

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WashcareAuthor Commented:
Sorry for my slow reply - super thank you!
0
WashcareAuthor Commented:
Thanks
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.