panther71 Posted August 8, 2011 Share Posted August 8, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/ Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 can you paste your code on this thread please.. Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254251 Share on other sites More sharing options...
panther71 Posted August 8, 2011 Author Share Posted August 8, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254254 Share on other sites More sharing options...
chandler Posted August 8, 2011 Share Posted August 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254281 Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254285 Share on other sites More sharing options...
panther71 Posted August 8, 2011 Author Share Posted August 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254288 Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254290 Share on other sites More sharing options...
chandler Posted August 8, 2011 Share Posted August 8, 2011 I found this tutorial maybe it will work better for you! http://php.about.com/od/phpapplications/ss/form_mail.htm Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254291 Share on other sites More sharing options...
panther71 Posted August 8, 2011 Author Share Posted August 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254295 Share on other sites More sharing options...
panther71 Posted August 8, 2011 Author Share Posted August 8, 2011 Hi Chandler, many many thanks. Even after a cursory flick throught he tutorial, I now see what error I made and what to do to fix it. I will post back as soon as I have done the necessary Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254303 Share on other sites More sharing options...
AyKay47 Posted August 8, 2011 Share Posted August 8, 2011 probably has something to do with the version of PHP you are using in correlation to the heredoc syntax? Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254305 Share on other sites More sharing options...
chandler Posted August 8, 2011 Share Posted August 8, 2011 Good, best of luck with it. Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254316 Share on other sites More sharing options...
panther71 Posted August 8, 2011 Author Share Posted August 8, 2011 Chandler: Many many thanks! After looking at the article you pointed out, a little re-writing of my script and the eventual correction of a capital T, it all works 100% :D Thank you once again Simon Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254346 Share on other sites More sharing options...
chandler Posted August 8, 2011 Share Posted August 8, 2011 you're welcome! Quote Link to comment https://forums.phpfreaks.com/topic/244212-contact-form-php-scripting/#findComment-1254518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.