im trying to create a feedback form that allows the user to select a recipent from a drop down menu so that once the send button is hit, the email is sent to the persons email address in the list. i have thelist created and have attempted the php handler but it doesnt seem to work. the page loads correctly as if the form has worked (i get the thankyou message) but the email does not send. could anyone please help me?

this is my form code:

<form id="form1" method="post" action="sendmail.php">
      <label>
      <div align="left"><span class="style1">Councillor:
        <select name="emailler" id="councillor">
            <option value="cllrckavanagh@sthelens.gov.uk">Carole</option>
            <option value="cllrferry@sthelens.gov.uk">Richard</option>
            <option value="cllraheyes@sthelens.gov.uk">Anne</option>
            <option value="snefmoo@hotmail.com">Stef</option>
      </select>
      </span></div>
      </label>
      <p align="left" class="style1">
        Your Name: 
        <input name="Name" type="text" value="" />
      </p>
      <p align="left" class="style1">Your Email Address:
        <input name="Name2" type="text" value="" />
</p>
      <p>
        <span class="style1">
        <label>
        Message: 
          <textarea name="msg" id="msg" cols="45" rows="5"></textarea>
          <br />
          <br />
          <input type="submit" name="send" id="send" value="Submit" />
          <input type="reset" name="delete" id="delete" value="Delete" />

        </label>
      </span> 
    </form>

and this is my attempt at the php:

<?php
if (isset($_REQUEST['emailler']))

  {

  $councillor = $_REQUEST['councillor'] ;
  $name = $_REQUEST['Name'] ;
  $email = $_REQUEST['Name2'] ; 
  $message = $_REQUEST['msg'] ;
  mail( "someone@example.com", "Name: $name",
  $message, "From: $email" );
  echo "Thank you for using our mail form";
  }
else

  {
  echo "<form method='post' action='sendmail.php'>
  Name: <input name='email' type='text' /><br />
  Email: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

it may be something simple that iv missed but iv been trying to fix it for a while now but i just cant see where iv gone wrong and its driving me crazy.
any help would be appreciated.

you have your emails sending to "someone@example.com". replace that with $councillor. After you do that, change the $_REQUEST to $_POST.

change if (isset($_REQUEST['emailler'])) to if (isset($_POST['send'])) i recommend using $_POST array instead of $_REQUEST because it more secure.

you need to make this much more secure before putting this live. add some validation. people can send an email to anyone through it.

Also your $_REQUEST is incorrect. It should be $_REQUEST or $_POST
I have made a few modifications to the php file to fix it up a bit and compact the code. Sorry if I confused you but the way I would do the code is something like the following:

<?php
if (isset($_POST['emailler'])) {
mail( $_POST['emailler'], 'Name: '.$_POST['Name'],
$_POST['msg'], "From: ".$_POST['Name2'] );
echo "Thank you for using our mail form";

} else {

echo "<form method='post' action='sendmail.php'>
Name: <input name='email' type='text' /><br />
Email: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>

Also I would suggest having a validator that checks if the message is empty and if the email provided has a valid domain. So that can be done with regex and curl. Also, code tags like I've used help make the code more readable. So please use code tags in the future. :)

hi this is nathen,its better to use foreach for your form because it reduces the lines of code,you just abserve this,first you take $_POST=$abc;
foreach($abc as $val)
{
mail($val);}
i think it will take every one into account and send the mails

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.