Jump to content

Recommended Posts

Okay,I need to update my email/contact form to

have a choice of 1 of 3 people to contact,and I am a noob

at this.Need some help.

 

Heres my form:

 

<h2>Contact The Webmaster</h2><br>

 

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

  Your Name:

  <input type="text" name="name" size="19"><br>

  <br>

  Your Email Address:

  <input type="text" name="email" size="19"><br>

  <br>

  Question/Comments:<br>

  <textarea rows="9" name="message" cols="30"></textarea>

 

  <br>

  <br>

  <input type="submit" value="Submit" name="submit">

</form>

 

 

Here's my php:

 

<?php

$to = "jondoe@gmail.com";

$subject = "Form Tutorial";

$name_field = $_POST['name'];

$email_field = $_POST['email'];

$message = $_POST['message'];

 

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

 

echo "";

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

 

 

 

// Change to the URL you want to redirect to

$URL="http://www.jondoe.org/thankyou.html";

 

header ("Location: $URL");

?>

 

Can I use checkboxes/dropdown and somehow make a

choice setting in my PHP code?

 

<head>
</head>

<body>
<form action="xx.php" method="post">
  <select name="person">
    <option value="person1@x.com">person 1</option>
    <option value="person2@x.com">person 2</option>
    <option value="person3@x.com">person 3</option>
  </select>
  <input type="submit" value="Send">
  </p>
</form>

<?php
if (isset($_POST['person'])) {
$person = $_POST['person'];
echo $person;
}
?>

</body>
</html>

 

and you should  validate the input, because of stupid spammers!

Just made this for you but it's probably not perfect:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Email Form</title>
</head>

<body>
<form action="xx.php" method="post">  <p>
    <label>your name<br />
    <input type="text" name="name" />
    </label>
    <br />
    <label>your email<br />
    <input type="text" name="email" />
    </label>
    <br />
    <label>message <br />
    <textarea name="comments"></textarea>
    </label>
    <br />
  Send to: <br />

  <select name="person">
    <option value="person1@x.com">person 1</option>
    <option value="person2@x.com">person 2</option>
    <option value="person3@x.com">person 3</option>
  </select>
  <br />
  <br />
  <input type="submit" value="Send">
  </p>
</form>

<?php

if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['comments']) && isset($_POST['person'])) { //check if all form data has been filled in

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$subject = 'Message From Visitor' ;
$mailto = $_POST['person'];
$http_referrer = getenv( "HTTP_REFERER" );
$uself = 1;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/";

if (!preg_match($regexp, $email)) {
       echo 'incorrect email format!';
       exit ;
}

$message =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $message,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: kelzback.php 1.0" );
echo 'your message has been send to ' . $mailto;
exit ;
}
?>

</body>
</html>

 

xx.php will be the name of this email form. so you should create a webpage called xx.php and paste this code in there. you can change the name but if you change the file to email.php don't forget to change the form action to "email.php" too!!

 

if you have problems adding this to your webpage i'll do it for you if you have me the source code of the page.. im so nice!^^

actually i havnt tested it so good luck!^^

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.