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
https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/
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 = '[email protected]';
#		switch($_POST["type"]){ $EmailTo = '[email protected]'; case "info": $EmailTo = '[email protected]'; case "procu": $EmailTo = '[email protected]'; case "sales": $EmailTo = '[email protected]'; case "it": $EmailTo = '[email protected]'; case "trans": $EmailTo = '[email protected]'; case "hr": $EmailTo = '[email protected]'; 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";

?>

When posting on these sites I would not include your email, use something like [email protected]. I recommend you modify your last post to remove it.

MY EMAIL IS [email protected]..  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?

When posting on these sites I would not include your email, use something like [email protected]. I recommend you modify your last post to remove it.

MY EMAIL IS [email protected]..  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?

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.

Archived

This topic is now archived and is closed to further replies.

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