simon71 Posted May 4, 2010 Share Posted May 4, 2010 Hi, Im new to PHP and contact forms so need some help getting my data collection form to work. Im hosting on Fasthost. My form action is '/htdocs/form/sendmail.php'. my script is: <?php $email_to="form@iter-research.co.uk"; $name=$_POST["Name"]; $email_from=$_POST["form@iter-research.co.uk"]; $message=$_POST["Name,Address,Postcode,Email,Gender,Age,Correspondence"]; $email_subject="Consultation Form"; $headers= "from:$email_from.\n"; "reply-to:$email_from.\n"; if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) { die("The email address entered is invalid."); $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, -f$email_from); if($sent) { header("Location: http://www.iter-rese...hank_you.html/"); } else { echo "There has been an error sending your message. Please try later."; } } ?> When i hit the submit button the browser just trys to open a new window with my PHP script in. I'm New to PHP and contact forms so if im doing something really basic and stupid i apologise in advance. has anyone got any suggestion?? Simon Quote Link to comment Share on other sites More sharing options...
siric Posted May 4, 2010 Share Posted May 4, 2010 Need the script for the form. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 4, 2010 Share Posted May 4, 2010 Try this. tidied it up a bit. It might be that your "TARGET" is _BLANK (In the FORM tag which is part the form) <?php $email_to = "form@iter-research.co.uk"; $name = $_POST["Name"]; $email_from = $_POST["form@iter-research.co.uk"]; $message = $_POST["Name"] . $_POST["Address"] . $_POST["Postcode"] . $_POST["Email"] . $_POST["Gender"] . $_POST["Age"] . $_POST["Correspondence"]; $email_subject = "Consultation Form"; $headers = "FROM: $email_from.\n" . "reply-to:$email_from.\n"; if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) { die("The email address entered is invalid."); } else { $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers); if($sent) { header("Location: http://www.iter-rese...hank_you.html/"); } else { echo "There has been an error sending your message. Please try later."; } } ?> $_POST["form@iter-research.co.uk"]; Do you seriously have a form field called that? Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 4, 2010 Author Share Posted May 4, 2010 The form Script is: <form action="/htdocs/form/sendmail.php" method="post" name="form1" target="_blank" id="form1"> <table width="100%" border="0" cellspacing="0" cellpadding="3"> <tr> <td width="38%"><label> <div align="right">Name</div> </label></td> <td width="62%"><input name="Name" type="text" id="Name" tabindex="1" size="50" /></td> </tr> <tr> <td><label> <div align="right">Address</div> </label></td> <td><textarea name="Address" cols="50" id="Address" tabindex="2"></textarea></td> </tr> <tr> <td><label> <div align="right">Postcode</div> </label></td> <td><input name="Postcode" type="text" id="Postcode" tabindex="3" /></td> </tr> <tr> <td><label> <div align="right">Email</div> </label></td> <td><input name="Email" type="text" id="Email" tabindex="4" size="50" /></td> </tr> <tr> <td><label> <div align="right">Gender</div> </label></td> <td><select name="Gender" size="1" id="Gender" tabindex="5"> <option value="1">Male</option> <option value="2">Female</option> <option value="0" selected="selected">Please Select</option> </select></td> </tr> <tr> <td><label> <div align="right">Age</div> </label></td> <td><select name="Age" size="1" id="Age"> <option value="0">Please Select</option> <option value="1"><16</option> <option value="2">17-20</option> <option value="3">21-25</option> <option value="4">26-30</option> <option value="5">31-35</option> <option value="6">36-40</option> <option value="7">41-45</option> <option value="8">46-50</option> <option value="9">50></option> </select></td> </tr> <tr> <td><label> <div align="right">Would you prefer any further correspondence to be in Welsh Or English </div> </label></td> <td><select name="Correspondence" size="1" id="Correspondence"> <option value="0">Please Select</option> <option value="1">Welsh</option> <option value="2">English</option> </select> <label> <input type="submit" name="Submit" value="Submit" /> <input name="Reset" type="reset" id="Reset" value="Reset" /> </label></td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 4, 2010 Share Posted May 4, 2010 Read my post. <form action="/htdocs/form/sendmail.php" method="post" name="form1" target="_blank" id="form1"> You have a _BLANK target. Remove the target... It'll be helpful. Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 I have removed the '_blank' and nothing has changed?? Any more ideas? Simon Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 <form action="/htdocs/form/sendmail.php" method="post" name="form1" id="form1"> The form action should look like that. Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 ive changed the code and still no change. im wondering if iPHP is enabled on my hosting account, even though according to fasthost it is included in my package?? Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 Oh I understand what you mean. On your form page.. just include something like this.. <?php echo 'It supports PHP'; ?> Then try it out, see if it echo's it. The filename extension should also be .php Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 Oh I understand what you mean. On your form page.. just include something like this.. <?php echo 'It supports PHP'; ?> Then try it out, see if it echo's it. The filename extension should also be .php Just did this and i got the 'it supports PHP' message back. What next?? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 in your form's 'action' remove the /htdocs from the front of it and give it a shot. Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 ive done that already. Still no change. If it of any help the link below take you to the form. www.iter-research.co.uk/GetInvolved Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 I can navigate directly to http://www.iter-research.co.uk/form/sendmail.php and it loads (blank page but that's to be expected). have you tried: action="../form/sendmail.php" Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 ive changed the code...still no change!! Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 <?php if(isset($_POST['Submit'])) { $email_to = "form@iter-research.co.uk"; $name = $_POST["Name"]; $email_from = $_POST["form@iter-research.co.uk"]; $message = $_POST["Name"] . $_POST["Address"] . $_POST["Postcode"] . $_POST["Email"] . $_POST["Gender"] . $_POST["Age"] . $_POST["Correspondence"]; $email_subject = "Consultation Form"; $headers = "FROM: $email_from.\n" . "reply-to:$email_from.\n"; if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) { die("The email address entered is invalid."); } else { $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers); if(isset($sent)) { header("Location: http://www.iter-rese...hank_you.html/"); } else { echo "There has been an error sending your message. Please try later."; } } } else { echo 'You never clicked the submit button!'; } ?> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 the submit button took me to the desired page, did you refresh your browser? However the page is still blank, can you turn error reporting to E_all? Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 Ive now changed the file to include teddykillers code, now all i get is email address is invalid when i hit submit Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 Change.. if(!filter_var($email_from, FILTER_VALIDATE_EMAIL)) { die("The email address entered is invalid."); } else { To this.. $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"."\.([a-z]{2,}){1}$"; if (!eregi($regex,($email_from))) { die("The email address entered is invalid."); } else { Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 code now reads: <?php if(isset($_POST['Submit'])) { $email_to = "form@iter-research.co.uk"; $name = $_POST["Name"]; $email_from = $_POST["form@iter-research.co.uk"]; $message = $_POST["Name"] . $_POST["Address"] . $_POST["Postcode"] . $_POST["Email"] . $_POST["Gender"] . $_POST["Age"] . $_POST["Correspondence"]; $email_subject = "Consultation Form"; $headers = "FROM: $email_from.\n" . "reply-to:$email_from.\n"; $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"."\.([a-z]{2,}){1}$"; if (!eregi($regex,($email_from))) { die("The email address entered is invalid."); } else { $message = "Name: ". $name . "\r\nMessage: " . $message; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers); if(isset($sent)) { header("Location: http://www.iter-rese...hank_you.html/"); } else { echo "There has been an error sending your message. Please try later."; } } } else { echo 'You never clicked the submit button!'; } ?> still get email address is invalid Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 Change... $_POST["form@iter-research.co.uk"]; to $_POST["Email"]; Quote Link to comment Share on other sites More sharing options...
simon71 Posted May 5, 2010 Author Share Posted May 5, 2010 The problem is now fixed. A HUGE thank you TeddyKiller Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 5, 2010 Share Posted May 5, 2010 RE: eregi() From the PHP manual: "This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged." Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 5, 2010 Share Posted May 5, 2010 RE: eregi() From the PHP manual: "This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged." What could be used instead? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 5, 2010 Share Posted May 5, 2010 PERL compatible regular expression (PCRE) functions, such as preg_match(). 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.