Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact form problem

Featured Replies

Hi

 

This is my first time on this forum but one of my mates swears by it!

 

Ok, I have a contact form set up but it currently only sends to one recipient. I want to allow the option to send to one of three recipients by using a simple dropdown.

 

This is the HTML

 

<form method="POST" action="contact.php">

<h2>Branch</h2>
<select size="1" name="branch">
<option>Bristol - Head Office</option>
<option>London</option>
<option>Birmingham</option>
</select>
<h2>Name</h2>
<input type="text" name="name" size="19">

<h2>Company</h2>
<input type="text" name="email" size="19">
<h2>Contact Tel</h2>
<input type="text" name="email" size="19">
<h2>E-mail</h2>
<input type="text" name="email" size="19">

<h2>Enquiry</h2>
<textarea rows="9" name="enquiry" cols="30"></textarea>
<br><br />

<input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset">
</form>

 

 

 

This is the PHP

 

<?php
if(isset($_POST['submit'])) {

$to = "alex@jumpcommunication.co.uk";
$subject = "Web Enquiry";
$name_field = $_POST['name'];
$company_field = $_POST['company'];
$contact_tel_field = $_POST['contact_tel'];
$email_field = $_POST['email'];
$enquiry = $_POST['enquiry'];
$dropdown = $_POST['drop_down'];

$body = "From: $name_field\n Company: $company_field\n Contact-Tel: $contact_tel_field\n E-Mail: $email_field\n Branch: $dropdown\n Enquiry: $enquiry\n";

mail($to, $subject, $body);

}
?>

 

 

I've tried so many ways but all just fail miserably.

 

Please help

 

Thanks

Welcome to the forum :)

 

I've probably misunderstood the question, but don't you just need a drop down box that passes the selected email address to the PHP script, and the email is then sent to this address?

  • Author

Thanks for the roply.

 

I'm not really sure how to set the different e-mail recipients in the script. As you can see all responses are currently sent to one e-mail, which is me.

 

I want to set up different e-mail recipients for the three branches Bristol, London and Birmingham that are in the existing drop down.

you should assign a value to the selections

 

<select size="1" name="branch">
<option value="bristol">Bristol - Head Office</option>
<option value="london">London</option>
<option value="bham">Birmingham</option>
</select>

 

then this line should be

 

$dropdown = $_POST['branch'];

 

For the third point try something like this

if ( $dropdown  == "bristol" ) {
$to = "bristol@jumpcommunication.co.uk";}
elseif ( $dropdown  == "london" ) {
$to = "london@jumpcommunication.co.uk";}
else  ( $dropdown  == "bham" ) {
$to = "bham@jumpcommunication.co.uk";}

 

 

That might not work, not so good with the php. But that's what i'd try to start with anyway.

Thanks for the roply.

 

I'm not really sure how to set the different e-mail recipients in the script. As you can see all responses are currently sent to one e-mail, which is me.

 

I want to set up different e-mail recipients for the three branches Bristol, London and Birmingham that are in the existing drop down.

 

Ahh I see. Yea, bocaj has it spot on there.

contact.html

<!--- Form Content =-->
<h2>Make an Enquiry?</h2>

<form method="post" action="sendmail.php">
<h3>Branch:</h3>
<select name="branch" size="1">
<option value="Bristol">Bristol</option>
<option value="London">London</option>
<option value="Birmingham">Birmingham</option>
</select>

<h3>Name:</h3>
<input type="text" name="visitor" size="35" />

<h3>Company:</h3>
<input type="text" name="company" size="35" />

<h3>Telephone Number:</h3>
<input type="text" name="telephone" size="35" />

<h3>Email:</h3>
<input type="text" name="visitormail" size="35" />

<h3>Enquiry:</h3>
<textarea name="enquiry" rows="9" cols="30"></textarea>
</div>

<p>
<input type="submit" value="Submit" />
<br />
<input type="reset" value="Reset">
</p>
</form>
<!--- /Form Content =-->

 

sendmail.php

<?php

$visitor = $_POST['visitor'];
$company = $_POST['company'];
$telephone = $_POST['telephone'];
$visitormail = $_POST['visitormail'];
$enquiry = $_POST['enquiry'];

$sendTo = "";
switch($_POST["branch"])
{
   case("Bristol"):
       $sendTo = "example@live.co.uk";
       break;

   case("London"):
       $sendTo = "example2@live.co.uk";
       break;

   case("Birmingham"):
       $sendTo = "example3@live.co.uk";
       break;

   default: //<-- It executes the default if none of the above are true
       $sendTo = "default@live.co.uk";
       break;
}
?>


<!--- Content =-->
<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
include 'errorpage.php';
die;
}

if(empty($visitor) || empty($visitormail) || empty($enquiry) || empty($telephone) || empty($company))
{
include 'errorpage.php';
die;
}
?>

<h1>Thanks for contacting us <?php echo $visitor ?>...</h1>
<!--- /Content =-->

<?php

$todayis = date("l, F j, Y, g:i a") ;

$subject = $company;

$enquiry = stripcslashes($enquiry);

$message = " $todayis [EST] \n
Branch: $branch \n
Enquiry: $enquiry \n
From: $visitor ($visitormail)\n
Company: $company \n
Telephone: $telephone \n
";

$from = "From: $visitormail\r\n";

mail($sendTo, $subject, $message, $from);
?>

 

Proof it works:

http://www.avalancheweb.co.uk/phpform/contact.html

 

Hope that helps

  • Author
contact.html

<!--- Form Content =-->
<h2>Make an Enquiry?</h2>

<form method="post" action="sendmail.php">
<h3>Branch:</h3>
<select name="branch" size="1">
<option value="Bristol">Bristol</option>
<option value="London">London</option>
<option value="Birmingham">Birmingham</option>
</select>

<h3>Name:</h3>
<input type="text" name="visitor" size="35" />

<h3>Company:</h3>
<input type="text" name="company" size="35" />

<h3>Telephone Number:</h3>
<input type="text" name="telephone" size="35" />

<h3>Email:</h3>
<input type="text" name="visitormail" size="35" />

<h3>Enquiry:</h3>
<textarea name="enquiry" rows="9" cols="30"></textarea>
</div>

<p>
<input type="submit" value="Submit" />
<br />
<input type="reset" value="Reset">
</p>
</form>
<!--- /Form Content =-->

 

sendmail.php

<?php

$visitor = $_POST['visitor'];
$company = $_POST['company'];
$telephone = $_POST['telephone'];
$visitormail = $_POST['visitormail'];
$enquiry = $_POST['enquiry'];

$sendTo = "";
switch($_POST["branch"])
{
   case("Bristol"):
       $sendTo = "example@live.co.uk";
       break;

   case("London"):
       $sendTo = "example2@live.co.uk";
       break;

   case("Birmingham"):
       $sendTo = "example3@live.co.uk";
       break;

   default: //<-- It executes the default if none of the above are true
       $sendTo = "default@live.co.uk";
       break;
}
?>


<!--- Content =-->
<?php
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
include 'errorpage.php';
die;
}

if(empty($visitor) || empty($visitormail) || empty($enquiry) || empty($telephone) || empty($company))
{
include 'errorpage.php';
die;
}
?>

<h1>Thanks for contacting us <?php echo $visitor ?>...</h1>
<!--- /Content =-->

<?php

$todayis = date("l, F j, Y, g:i a") ;

$subject = $company;

$enquiry = stripcslashes($enquiry);

$message = " $todayis [EST] \n
Branch: $branch \n
Enquiry: $enquiry \n
From: $visitor ($visitormail)\n
Company: $company \n
Telephone: $telephone \n
";

$from = "From: $visitormail\r\n";

mail($sendTo, $subject, $message, $from);
?>

 

Proof it works:

http://www.avalancheweb.co.uk/phpform/contact.html

 

Hope that helps

 

Thanks very much guys, you have all been a great help.

 

Just one thing. Are these forms safe from spammers?

 

If not could you suggest how i could protect from this?

 

Thanks again

 

OD

By the looks of his form it has validation rules, so it requires legitimate detail.

 

Now the golden question of spam :p

 

There's dozens of methods, but they all have issues. Captcha's can be broken, and they're just a pain (it took me about 6 attempts to work out googles, they are by far the worst captcha's i've ever seen!) honey pots have accessibility flaws and so on.

 

Weigh up the pro's and con's, but you don't actually need to implement anything until you start getting problematic spam (one a week is liveable, 40 a day isn't).

 

Too many people who have small blogs, who don't receive spam anyway, go and install captcha's because they think they're supposed too, captcha's are one of the most irritating things on the internet.

  • Author
By the looks of his form it has validation rules, so it requires legitimate detail.

 

Now the golden question of spam :p

 

There's dozens of methods, but they all have issues. Captcha's can be broken, and they're just a pain (it took me about 6 attempts to work out googles, they are by far the worst captcha's i've ever seen!) honey pots have accessibility flaws and so on.

 

Weigh up the pro's and con's, but you don't actually need to implement anything until you start getting problematic spam (one a week is liveable, 40 a day isn't).

 

Too many people who have small blogs, who don't receive spam anyway, go and install captcha's because they think they're supposed too, captcha's are one of the most irritating things on the internet.

 

Thanks Bocaj, I'll leave it for a while to see how I get on.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.