Jump to content

[SOLVED] Contact form with drop-down menu


soycharliente

Recommended Posts

Well any general form tutorial will do what you need. In this case, you would build a completely normal drop down box in the HTML, then on the PHP end you would have it check what the user selected, then send.

 

Take a look at this:

 

http://www.tizag.com/phpT/examples/formex.php

You don't want to do anything like this:

form_handler.php

<?php
  $sel = $_POST['selected'];
  if($sel == "Bob"){
    // Do bob stuff
  }else if($sel == "Sally"){
    // Do sally stuff
  }else if($sel == "Fred"){
    // Do fred stuff
  }
  // ...and so on.
?>

 

It's very inefficient, tedious to type, and impossible to maintain.

 

Instead set the value attribute of the form options to an appropriate value, such as the e-mail address of the recipient.

form

<select name="recipient">
  <option value="[email protected]">Bob</option>
  <option value="[email protected]">Sally</option>
  <option value="[email protected]">Fred</option>
</select>

 

form_handler.php

<?php
  $email = $_POST['recipient'];
  mail($email, "Hi2u", "Hello, World!");
?>

try this ok .

 

<?php
$db=mysql_connect("localhost","username","password");
mysql_select_db("database_name",$db);


$query="select * form what_ever where email='$email'";

$result=mysql_fetch_assoc($query);

echo"<form='method='POST' action=''> <option name='email'>";

while($x=mysql_fetch_assoc($result)){

echo"<option value='".$x['email']."'>".$x['email']."</option>";
}

echo"<input type='submit' name='submit' value='email members'></select>

</form></option>";


if($_POST['submit']){

$to = $email;

$subject = 'hi it redarrow!';

$message = '<b>yo</b>, how are you mate';

$headers = "From: redarrow@what_ever.com\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

if(mail($to, $subject, $message, $headers)){

echo " cheers email sent to: $email ";
}

}else{

echo" sorry no email sent";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.