oggyswain Posted April 20, 2010 Report Share Posted April 20, 2010 I am trying to have the form I've created emailed to a specific email address. How do I do it? Thanks Here is the form code <div class="wrapper"> <div class="col-1"> <div class="form"> <input type="text" value="Name:" onfocus="if(this.value=='Name:'){this.value=''}" onblur="if(this.value==''){this.value='Name:'}" /> </div> <div class="form"> <input type="text" value="E-mail:" onfocus="if(this.value=='E-mail:'){this.value=''}" onblur="if(this.value==''){this.value='E-mail:'}" /> </div> <div class="form"> <input type="text" value="Fax:" onfocus="if(this.value=='Fax:'){this.value=''}" onblur="if(this.value==''){this.value='Fax:'}" /> </div> </div> <div class="col-2"> <div> <textarea cols="1" rows="1">Message:</textarea> </div> <div class="wrapper"><a href="#" class="link" onclick="document.getElementById('contacts-form').submit()">submit</a><a href="#" class="link" onclick="document.getElementById('contacts-form').reset()">reset</a></div> </div> </div> Quote Link to comment Share on other sites More sharing options...
Wickham Posted April 20, 2010 Report Share Posted April 20, 2010 Why are you using javascript like onfocus and onblur? Your form won't be usable by people with javascript/ActiveX disabled. You aren't using a form, you're using a div class="form" which isn't the same. Why not use a simple form with an action to a mailto email address like one shown here:- http://www.wickham43.net/forms.php or here from a webform without needing an email client on the viewer's computer:- http://www.wickham43.net/formemail.php Quote Link to comment Share on other sites More sharing options...
oggyswain Posted April 21, 2010 Author Report Share Posted April 21, 2010 It's from a template. I will try the one you suggested. Thanks Quote Link to comment Share on other sites More sharing options...
oggyswain Posted April 28, 2010 Author Report Share Posted April 28, 2010 Hi Wickham, Would someone not be able to "Troll" for the the email address? I just worry about getting more spam than I already do. Quote Link to comment Share on other sites More sharing options...
Wickham Posted April 28, 2010 Report Share Posted April 28, 2010 The first link in my previous post uses <form action="mailto:your-name@hotmail.com" method="post"> and the mailto code will attract spambots unless you use javascript to break up the email address so that it's very difficult for spambots to re-assemble the address (most won't bother as they can harvest enough mailto addresses that haven't been coded with javascript). See the second last paragraph of item 1a. The second link in my previous post uses a separate PHP page with your email address that cannot be seen by spambots as it's processed by the server without being displayed or shown in the page source code. Quote Link to comment Share on other sites More sharing options...
oggyswain Posted April 28, 2010 Author Report Share Posted April 28, 2010 Hi Mr. Wickham, I downloaded sendmail.php. Added it to my site. It is not working. Could you take a look and see what I have managed to screw up,. www.urbanmail.ca/contact_us.html Thanks Here is the sendmail.php script <?php //<!-- //------------------------------------- //- Feedback Form - //- copyright © James Coyle; JCcorp - //- JCcorp.net - //- Release 25-07-2006 - //- Ver 1.0.1 - //------------------------------------- //--> //<!--See http://www.killersites.com/mvnforum/mvnforum/viewthread?thread=10257 ewwatson 30/04/08 //--> // Edit the below fields $admin = 'info@urbanmail.ca' ; // Change to your admin email 'from' address $replymsg = 'Thank you for your email. We will respond shortly.' ; // Reply message to send $formurl = 'http://www.urbanmail.ca/sendmail.php' ; // the URL where the form code is - default: form.php $errorurl = 'error.html' ; // the URL to show on error - default error.html $thankyouurl = 'thankyou.html' ; // the URL to show feedback submitted - default: thankyou.html // Security code to prevent addition of extra emails by spambots function remove_headers($string) { $headers = array( "/to\:/i", "/from\:/i", "/bcc\:/i", "/cc\:/i", "/Content\-Transfer\-Encoding\:/i", "/Content\-Type\:/i", "/Mime\-Version\:/i" ); if (preg_replace($headers, '', $string) == $string) { return $string; } else { die('You are not completing the form correctly.'); } } $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; // Variables $email = remove_headers($_REQUEST['email']) ; $name = remove_headers($_REQUEST['name']) ; $subject = remove_headers($_REQUEST['subject']) ; $message = remove_headers($_REQUEST['message']) ; $wordcount = str_word_count($message); $component = ($_REQUEST['component']) ; $size =($_REQUEST['size']) ; $delivery = ($_REQUEST['delivery']) ; $confirmation = ($_REQUEST['confirmation']) ; // Code to prevent addition of / before ' in text entered by viewer if (get_magic_quotes_gpc()) { $name = stripslashes( $name ); $subject = stripslashes( $subject ); $message = stripslashes( $message ); } // If email is filled out, proceed, if not, display the form if (!isset($_REQUEST['email'])) { header( "Location: $formurl" ); // } // If a bot is attempting to send spam it will complete this input while viewers don't see the visibility: hidden box elseif ($_REQUEST['catchbot'] !="") { //Boot it out of the server die(); } // Code to check for empty input boxes elseif (empty($email) || empty($name) || empty($subject) || empty($component) || empty($size)) { header( "Location: $errorurl" ); } // Security code to check that email address is probably valid and only contains one address elseif (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$email)) { header( "Location: $errorurl" ); exit ; } // Security code to prevent addition of new lines entered into the $name and $email fields by spambots elseif ( preg_match( "[\r\n]", $name ) || preg_match( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } elseif ($wordcount >50) { echo "Please do not exceed fifty words."; } //WORDCOUNT ADDED but . in a word like formemail.php causes extra word; echo will show in plain text in a new window with default browser background color (an alternative to header( "Location: $errorurl" ); which shows a complete html page) else { mail( $admin, "Feedback: $subject", "$name\r\n$message\r\n$component $size\r\n$delivery\r\n$confirmation", "From: $name <$email>" ); mail( $email, "Feedback: $subject", $replymsg , "From: $admin" ); header( "Location: $thankyouurl" ); } ?> Quote Link to comment Share on other sites More sharing options...
Wickham Posted April 29, 2010 Report Share Posted April 29, 2010 My code does work, except that I've disabled the form in my tutorial. You have copied my sendmail.php in total and you've edited your admin email address as you should. However, are you sure your form fields are the same as in my example? These probably need editing but your html file url doesn't work so I can't check. Check that your hosting service supports PHP. My example is only the basic codes. If you have trouble with a spambot you will probably need additional security codes and it's often better to stat with a professional script that has security built in, like http://www.formmail.com/ or http://www.email-form.com/ or http://www.jemjabella.co.uk/php-scripts-php-mail-form Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.