Hej. Jeg har et downloadet et freeware PHP mailscript. Alting virker fint med hensyn til at redirecte, og validere osv. Den er error-fri.
Det eneste problem er at jeg ikke modtager min mail!
HTML-koden:
- <form name="freecontactform" method="post" action="freecontactformprocess.php" onsubmit="return validate.check(this)">
- <table width="400px" class="freecontactform">
- <tr>
- <td colspan="2">
-
- <div class="freecontactformheader">Contact Us Form</div>
-
- <div class="freecontactformmessage">Fields marked with <span class="required_star"> * </span> are mandatory.</div>
-
- </td>
- </tr>
- <tr>
- <td valign="top">
- <label for="Full_Name" class="required">Full Name<span class="required_star"> * </span></label>
- </td>
- <td valign="top">
- <input type="text" name="Full_Name" id="Full_Name" maxlength="80" style="width:230px">
- </td>
- </tr>
- <tr>
- <td valign="top">
- <label for="Email_Address" class="required">Email Address<span class="required_star"> * </span></label>
- </td>
- <td valign="top">
- <input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:230px">
- </td>
- </tr>
- <tr>
- <td valign="top">
- <label for="Telephone_Number" class="not-required">Telephone Number</label>
- </td>
- <td valign="top">
- <input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:230px">
- </td>
- </tr>
- <tr>
- <td valign="top">
- <label for="Your_Message" class="required">Your Message<span class="required_star"> * </span></label>
- </td>
- <td valign="top">
- <textarea style="width:230px;height:160px" name="Your_Message" id="Your_Message" maxlength="2000"></textarea>
- </td>
- </tr>
- <tr>
- <td colspan="2" style="text-align:center" >
- <div class="antispammessage">
- To help prevent automated spam, please answer this question
- <br /><br />
- <div class="antispamquestion">
- <span class="required_star"> * </span>
- Using only numbers, what is 10 plus 15?
- <input type="text" name="AntiSpam" id="AntiSpam" maxlength="100" style="width:30px">
- </div>
- </div>
- </td>
- </tr>
- <tr>
- <td colspan="2" style="text-align:center" >
- <br /><br />
- <input type="submit" value=" Submit Form " style="width:200px;height:40px">
- <br /><br />
Include koden:
- <script src="freecontactformvalidation.js"></script>
- <script>
- required.add('Full_Name','NOT_EMPTY','Full Name');
- required.add('Email_Address','EMAIL','Email Address');
- required.add('Your_Message','NOT_EMPTY','Your Message');
- required.add('AntiSpam','NOT_EMPTY','Anti-Spam Question');
- </script>
- <link rel="stylesheet" type="text/css" href="freecontactform.css">
Fil 1: freecontactformprocess.php
- <?php
- /**
- *
- * URL: www.freecontactform.com
- *
- * Version: FreeContactForm Free V2.1
- *
- * Copyright (c) 2012 Stuart Cochrane
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- *
- * Note: This is NOT the same code as the PRO version
- *
- */
-
- if(isset($_POST['Email_Address'])) {
-
- include 'freecontactformsettings.php';
-
- function died($error) {
- echo "Sorry, but there were error(s) found with the form you submitted. ";
- echo "These errors appear below.<br /><br />";
- echo $error."<br /><br />";
- echo "Please go back and fix these errors.<br /><br />";
- die();
- }
-
- if(!isset($_POST['Full_Name']) ||
- !isset($_POST['Email_Address']) ||
- !isset($_POST['Telephone_Number']) ||
- !isset($_POST['Your_Message']) ||
- !isset($_POST['AntiSpam'])
- ) {
- died('Sorry, there appears to be a problem with your form submission.');
- }
-
- $full_name = $_POST['Full_Name']; // required
- $email_from = $_POST['Email_Address']; // required
- $telephone = $_POST['Telephone_Number']; // not required
- $comments = $_POST['Your_Message']; // required
- $antispam = $_POST['AntiSpam']; // required
-
- $error_message = "";
-
- $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
- if(preg_match($email_exp,$email_from)==0) {
- $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
- }
- if(strlen($full_name) < 2) {
- $error_message .= 'Your Name does not appear to be valid.<br />';
- }
- if(strlen($comments) < 2) {
- $error_message .= 'The Comments you entered do not appear to be valid.<br />';
- }
-
- if($antispam <> $antispam_answer) {
- $error_message .= 'The Anti-Spam answer you entered is not correct.<br />';
- }
-
- if(strlen($error_message) > 0) {
- died($error_message);
- }
- $email_message = "Form details below.\r\n";
-
- function clean_string($string) {
- $bad = array("content-type","bcc:","to:","cc:");
- return str_replace($bad,"",$string);
- }
-
- $email_message .= "Full Name: ".clean_string($full_name)."\r\n";
- $email_message .= "Email: ".clean_string($email_from)."\r\n";
- $email_message .= "Telephone: ".clean_string($telephone)."\r\n";
- $email_message .= "Message: ".clean_string($comments)."\r\n";
-
- $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: $thankyou");
- ?>
- <script>location.replace('<?php echo $thankyou;?>')</script>
- <?php
- }
- die();
- ?>
Fil 2: freecontactformsettings.php
- <?php
-
- $email_to = "pasdrengen@gmail.com"; // your email address
- $email_subject = "Bloggernetwork - Ansøgning"; // email subject line
- $thankyou = "thankyou.htm"; // thank you page
-
- // if you update the question on the form -
- // you need to update the questions answer below
- $antispam_answer = "25";
-
- ?>
Fil 3: freecontactformvalidation.js
- // URL: www.freecontactform.com
- // Version: FreeContactForm V2.2
- // Copyright (c) 2012 Stuart Cochrane
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
- return true;}
- function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
- return true;}
- function $$(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;}
- if(has_id(id)){return document.getElementById(id).value;}else{return;}}
- function $val(id){return document.getElementById(id);}
- function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');}
- var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\n';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];}
- tmp=false;}}
- if(!tmp){alert(error_message);}
- if(to_focus.length>0){document.getElementById(to_focus).focus();}
- return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};
Sidste FIL: thankyou.htm
- <!--
- PLEASE REPLACE THIS WITH YOUR OWN THANK YOU
- -->
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Thank You</title>
- </head>
- <body>
- <h1>Thank You.</h1>
- <p>We have received your message.</p>
- </body>
- </html>
Håber nogle kan spotte fejlen, for jeg kan ikke