Jump to content

PHP - Multiple If Statements


Kadage

Recommended Posts

Hey everyone, i am currently working on a "contact us" script. I want the form to first allow the user which department they want to email. E.g. "Sales" and "Support" By changing this drop down box it will change which email the form is sent to. Im having trouble setting the PHP side of this script up to change the emails. Any help regarding this matter is much appreciated.

 

HTML FORM:

<form name="contactForm" method="post"  action="forms/contactUs.php">
                        <table width="350" border="0">
                            <tr>
                                <td width="150" class="bold">Department:</td>
                                <td width="200" align="left">
                                	<select name="department" class="dropDown">
                                	  <option value="sales">Sales</option>
                                	  <option value="support">Support</option>
                                    </select>
                            	</td>
                            </tr>
                            <tr>
                                <td class="bold">Full Name:</td>
                                <td>
                                	<input name="name" type="text" class="contactTextBox"  />
                                </td>
                            </tr>
                            <tr>
                                <td class="bold">Company:</td>
                                <td>
                                	<input name="company" type="text" class="contactTextBox" />
                                </td>
                            </tr>
                            <tr>
                                <td class="bold">Email:</td>
                                <td>
                                	<input name="email" type="text" class="contactTextBox" />
                                </td>
                            </tr>
                            <tr>
                                <td class="bold">Comments:</td>
                                <td>
                                	<textarea name="com" id="com" cols="5" rows="5" class="contactTextArea" /></textarea>
                                </td>
                            </tr>
                            <tr>
                                <td> 
                                	                                	
                                </td>
                                <td align="right">
                                	<input type="submit" class="button" value="Submit"  /> <input type="reset" class="button" value="Reset"  />
                                </td>
                            </tr>
                        </table>
				</form>

PHP

<?php

$department = $_POST['department'];
$confirm = "sales";

if(isset($_POST['email'])) {
	if($department == $confirm) {
		$email_to = "sales@pixemadesigns.com";
		$email_subject = "Sales Question";
	}
	else 
	{
		$email_to = "support@pixemadesigns.com";
		$email_subject = "Support Question";
	}

	$fullName = $_POST['name'];
	$company = $_POST['company'];
	$email_from = $_POST['email'];
	$comments = $_POST['com'];

	$email_message = "Form details below.\n\n";

	function clean_string($string) {
	  $bad = array("content-type","bcc:","to:","cc:","href");
	  return str_replace($bad,"",$string);
	}

	$email_message .= "Full Name: ".clean_string($fullName)."\n";
	$email_message .= "Company: ".clean_string($company)."\n";
	$email_message .= "Email: ".clean_string($email_from)."\n";
	$email_message .= "Comments: ".clean_string($comments)."\n";


	// create email headers
	$headers = 'From: '.$email_from."\r\n".
	'Reply-To: '.$email_from."\r\n" .
	'X-Mailer: PHP/' . phpversion();
	@mail($email_to, $email_subject, $email_message, $headers);  

	header("location: ../contactSubmit.html");

?>



<?
}
?>

Link to comment
Share on other sites

this is what i do to check functions and such.

the post vars are passing over and ur if is working.

sorry not more help. i dont have email on my test server.

 

<?php	

$confirm = "sales";	
$department = $_POST['department'];
$fullName = $_POST['name'];		
$company = $_POST['company'];		
$email_from = $_POST['email'];		
$comments = $_POST['com'];				

echo "$fullName";
echo "<br>";
echo "$company";
echo "<br>";
echo "$email_from";
echo "<br>";
echo "$comments";
echo "<br>";
echo "$department";
echo "<br>";

if(isset($_POST['email'])) {		
if($department == $confirm) {			
    $email_to = "sales@pixemadesigns.com";			
    $email_subject = "Sales Question";
    echo "match";		}		
   else 		{			
     $email_to = "support@pixemadesigns.com";			
     $email_subject = "Support Question";
     echo "error";		    
     }	
     			
$email_message = "Form details below.\n\n";		
function clean_string($string) {		  
$bad = array("content-type","bcc:","to:","cc:","href");		  
return str_replace($bad,"",$string);		}				
$email_message .= "Full Name: ".clean_string($fullName)."\n";		
$email_message .= "Company: ".clean_string($company)."\n";		
$email_message .= "Email: ".clean_string($email_from)."\n";		
$email_message .= "Comments: ".clean_string($comments)."\n";						
// create email headers		
$headers = 'From: '.$email_from."\r\n".		'Reply-To: '.$email_from."\r\n" .		'X-Mailer: PHP/' . phpversion();		
@mail($email_to, $email_subject, $email_message, $headers);  			
//header("location: ../contactSubmit.html");?>
<?php
echo "<br>";
echo "$headers";
echo "<br>";
echo "$email_message";
}
?>

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.