Jump to content

[SOLVED] Contact Form Help


dare87

Recommended Posts

I have an email form and it works great. I would like to make some modifications and I am having trouble. Instead of just sending the email to the person that I set I want them to be able to choose them from a list.

 

Thanks

 

<?php
			if (!isset($_POST['submit'])) 
			{
				// Show the form.
				echo '<form action="contact.php" method="post">
				<fieldset><legend>Contact Us</legend>

				<table align="center" width="100%"  border="0" cellspacing="0" cellpadding="0">
				<tr>
				<td align="left"><b>Name:</b></td>
				<td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td>
				</tr>
				<tr>
				<td align="left"><b>Email Address:</b></td>
				<td align="left"><input type="text" class="required" name="email" size="40" value="'.$email.'" maxlength="40" /></td>
				</tr>
				<tr>
				<td align="left"><b>Subject:</b></td>
				<td align="left"><input type="text" class="required" name="subject" size="40" value="'.$subject.'" maxlength="40" /></td>
				</tr>
				<tr>
				<td align="left"><b>Message:</b></td>
				<td align="left"><textarea class="required" name="body" rows="4" cols="40">'. $body.'</textarea></td>
				</tr>
				</table>	
				</fieldset>
				<div align="left">
				<input type="submit" class="button" name="submit" value="Send Message" /></div>
				<input type="hidden" class="button" name="submitted" value="TRUE" />
				</form>';
				echo 'All fields are required.';
				} else {

				// Validate the name and combat Magic Quotes.
				if (!empty($_REQUEST['name'])) {
					$name = stripslashes($_REQUEST['name']);
				}

				// Validate the email.
				if (!empty($_REQUEST['email'])) {
					$email = $_REQUEST['email'];
				}

				// Validate Subject.
				if (!empty($_REQUEST['subject'])) {
					$subject = $_REQUEST['subject'];
				}

				// Validate Message and combat Magic Quotes.
				if (!empty($_REQUEST['body'])) {
					$body = stripslashes($_REQUEST['body']);
				}

				// If everything has a value, check the email syntax.
				if ($name && $email && $subject && $body) {
					// Validate the email syntax.
					list($username,$domain) = split("@",$email);
					if (eregi ('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $_POST['email'])) {
						echo "<p>Thank you, $name. We will reply to your message at $email. <br /></p>";
						$headers = "From: {$_POST['name']}\r\n";
						$headers .= "Reply-To: {$_POST['email']}\r\n";
						mail ('email@email.com', $subject, $body, $headers);
					} else {
						echo '<p><font color="red"><strong>Please enter a valid e-mail address.</strong></font></p>';
						echo '<form action="contact.php" method="post">
						<fieldset><legend>Contact Us</legend>

						<table width="100%"  border="0" cellspacing="0" cellpadding="0">
						<tr>
						<td align="left"><b>Name:</b></td>
						<td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td>
						</tr>
						<tr>
						<td align="left"><b>Email Address:</b></td>
						<td align="left"><input type="text" class="required" name="email" size="40" 
						value="'.$email.'" maxlength="40" /></td>
						</tr>
						<tr>
						<td align="left"><b>Subject:</b></td>
						<td align="left"><input type="text" class="required" name="subject" size="40" 
						value="'.$subject.'" maxlength="40" /></td>
						</tr>
						<tr>
						<td align="left"><b>Message:</b></td>
						<td align="left"><textarea class="required" name="body" rows="4" cols="40">'. 
						$body.'</textarea></td>
						</tr>
						</table>
						</fieldset>
						<div align="left">
						<input type="submit" class="button" name="submit" value="Send Message" /></div>
						<input type="hidden" name="submitted" value="TRUE" />
						</form>';
						echo 'All fields are required.';
						}
				} else {
					echo '<p><font color="red"><strong>You forgot to enter one or more required fields.</strong></font></p>';
					echo '<form action="contact.php" method="post">
					<fieldset><legend>Contact Us</legend>

					<table width="100%"  border="0" cellspacing="0" cellpadding="0">
					<tr>
					<td align="left"><b>Name:</b></td>
					<td align="left"><input type="text" class="required" name="name" size="20" value="'.$name.'" maxlength="40" /></td>
					</tr>
					<tr>
					<td align="left"><b>Email Address:</b></td>
					<td align="left"><input type="text" class="required" name="email" size="40" 
					value="'.$email.'" maxlength="40" /></td>
					</tr>
					<tr>
					<td align="left"><b>Subject:</b></td>
					<td align="left"><input type="text" class="required" name="subject" size="40" 
					value="'.$subject.'" maxlength="40" /></td>
					</tr>
					<tr>
					<td align="left"><b>Message:</b></td>
					<td align="left"><textarea class="required" name="body" rows="4" cols="40">'. 
					$body.'</textarea></td>
					</tr>
					</table>
					</fieldset>
					<div align="left">
					<input type="submit" class="button" name="submit" value="Send Message" /></div>
					<input type="hidden" class="button" name="submitted" value="TRUE" />
					</form>';
					echo 'All fields are required.';
				}

			} // End of main isset() IF.
			?>

Link to comment
Share on other sites

Hi Mate,

 

just make a drop down box with different emails:

 

<?php
<select name="emails">
<option value="email1">email1</option>
<option value="email2">email2</option>
</select>

## grab the email
$emailtosendto = mysql_real_escape_string($_POST['emails']);

## then in the mail part do something like
$to = $emailtosendto;
?>

 

is that kinda what you were after?

 

Graham

Link to comment
Share on other sites

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.