Jump to content

Contact form PHP scripting


panther71

Recommended Posts

Hi there.

 

I was wondering if anyone out there could help me out a little.

 

I am trying to build a contact form for our website, and the form itself works OK. It posts various details to a PHP script that turns it all into an email, then the PHP re-directs back to the contact page. Now all of this works fabulously. I have grabbed the working script from Nate over at Tutvid - a truly wonderful guy with some great video tutorials.

 

My problem is this: I have a drop down box that the user can specify which department they would want to contact, there are 7 options. I want to send the email to the department chosen. Now, to that end I have found another script that says it will do this and I tried to merge it in, but when I type it in to Dreamweaver it says it has a script error and wont run.

 

I have attached the PHP script file, I have also commented out the section that has the error, and left in the section that actually works.

 

I am using Dreamweaver CS5.5, Windows Server 2008 with Exchange 2007 running on it, and all the web stuff is served with IIS. I really do not want to have to create a database to do this, and I do not want to fudge my install of exchange either, I simply want to send an email to a recipient based on a drop down.

 

I should point out that this is my first foray into the world of PHP/HTML/CSS, and I think I have a reasonable handle on it for a first time learner, but I seem to have hit a bit of a wall on this one, so any help would be greatly appreciated.

 

Many thanks in anticipation

 

Simon

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

hi

 

Sorry, thought attaching it would be ok.

 

Many thanks

 

Simon

 

<?php

# Subject and enail Values

    	$emailSubject =	'Webenquiry from Fesa.co.uk';
        $EmailTo = 'panther@fesatest.co.uk';
#		switch($_POST["type"]){ $EmailTo = 'info@fesatest.co.uk'; case "info": $EmailTo = 'procu@fesatest.co.uk'; case "procu": $EmailTo = 'sales@fesatest.co.uk'; case "sales": $EmailTo = 'it@fesatest.co.uk'; case "it": $EmailTo = 'trans@fesatest.co.uk'; case "trans": $EmailTo = 'hr@fesatest.co.uk'; case "hr": $EmailTo = 'quality@fesatest.co.uk'; case "quality":}
       
# Gathering Data Variables

	$emailField = $_POST['email'];
	$nameField = $_POST['name'];
	$companyField = $_POST['company'];
	$deptField = $_POST['dept'];
	$commentField = $_POST['comment'];

	$body = <<<EOD
<br><hr><br>
Email: $emailField <br>
Name: $nameField <br>
Company: $companyField <br>
Attn: $deptField <br>
Comments: $commentField <br>
EOD;

$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($EmailTo, $emailSubject, $body, $headers);


# Results rendered as HTML

$theResults = <<<EOD
<html>
<head>
<meta http-equiv="refresh" content="3;URL=http://fesatest.co.uk/contact.html">
<title>Success!!</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
background-image: url(Images/bgf2.jpg);
background-repeat: repeat-x;
left: auto;
right: auto;
clip: rect(auto,auto,auto,auto);
text-decoration: none;
font-size: 36px;
color: #000000;
}
</style>
</head>
<div>
<div align="center">Success! We Have received your form successfully. Please wait until the page re-directs you.</div>
    </div>
</body>
</html>
EOD;

echo "$theResults";

?>

Link to comment
Share on other sites

When posting on these sites I would not include your email, use something like example@example.co.uk. I recommend you modify your last post to remove it.

MY EMAIL IS NUJASQUIRREL14@MSN.COM..  email me

 

OP, one thing I suggest is that you check to make sure that all of the required fields are filled out before attempting to use them...something like.

 

if(!empty($emailField = $_POST['email']) && !empty($emailField = $_POST['name']) && !empty($emailField = $_POST['company']) && !empty($emailField = $_POST['dept']) && !empty($emailField = $_POST['comment'])){
// continue to send mail
}else{
// all required fields are not filled out..
}

 

Also, what errors are you receving?

do you have error_reporting set to E_ALL?

Link to comment
Share on other sites

Hi

 

The email address in the script is actually a dummy one, also, the form is configured to validate itself before it posts, so all fields are required in order for the form to successfully post itself, otherwise the user gets an error.

 

Simon

 

Link to comment
Share on other sites

When posting on these sites I would not include your email, use something like example@example.co.uk. I recommend you modify your last post to remove it.

MY EMAIL IS NUJASQUIRREL14@MSN.COM..  email me

 

OP, one thing I suggest is that you check to make sure that all of the required fields are filled out before attempting to use them...something like.

 

if(!empty($emailField = $_POST['email']) && !empty($emailField = $_POST['name']) && !empty($emailField = $_POST['company']) && !empty($emailField = $_POST['dept']) && !empty($emailField = $_POST['comment'])){
// continue to send mail
}else{
// all required fields are not filled out..
}

 

Also, what errors are you receving?

do you have error_reporting set to E_ALL?

Link to comment
Share on other sites

I get an error in the browser of:

Server error

The website encountered an error while retrieving http://fesatest.co.uk/fesatest.php. It may be down for maintenance or configured incorrectly.

Here are some suggestions:

Reload this web page later.

 

I dont get the error if i comment out my add-in and use the original

 

Thanks Chandler, I will check out the video you suggested.

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.