February 28, 200818 yr Hi guys, as a complete beginner I am scratching my head as to what I need to do to get the contact form on my website working! I know I'm probably being completely stupid but hey, we all gotto start somewhere right! <form id="contact" action="mailto:info@webexpress-uk.com" method="post" onsubmit="return configForm(this);" style="position: relative; z-index: 1;"> <p> <input type="text" name="name" value="Name" class="width75" onfocus="clearValue(this, 'Name');" onblur="fillValue(this, 'Name');"/> </p> <p> <input type="text" name="email" value="E-mail" class="width75" onfocus="clearValue(this, 'E-mail');" onblur="fillValue(this, 'E-mail');"/> </p> <p> <input type="text" name="subject" value="Subject" class="width75" onfocus="clearValue(this, 'Subject');" onblur="fillValue(this, 'Subject');"/> </p> <p> <textarea name="message" rows="5" cols="80" onfocus="clearValue(this, 'Message');" onblur="fillValue(this, 'Message');">Message</textarea> </p> <p> <input type="submit" value="SEND" class="button" /> <input type="reset" value="RESET" class="button" /> </p> <p> </form> Thank you!!
February 28, 200818 yr Author Sh...! This was meant to be posted in the How do I do that forum, sorry!! Way to go AL!! I would still like an answer though pretty please! Thank you!
February 28, 200818 yr You'll have a lot of problems with the "mailto" in the action attribute. This only works when people have their default mail client configured (outlook, thunderbird, etc.). People using web-based email clients won't be able to use your form.
February 28, 200818 yr Sh...! This was meant to be posted in the How do I do that forum, sorry!! Way to go AL!! I would still like an answer though pretty please! Thank you! No answer from me, but thread is now where you wanted it
February 28, 200818 yr Does your host have PHP support? http://www.tutorialtastic.co.uk/tutorial/p...e_and_protected
February 28, 200818 yr Author Hi Rachel, yes it does but I'm vrey much a beginner at this and would really appreciate a layman's tutorial. Even your kind post has made me cross eyed! Here's my amended code for the HTML, but I'm stuck on the PHP side of things! <form id="contact" action="form.php" method="post" onsubmit="return configForm(this);" style="position: relative; z-index: 1;"> <p> <input type="text" name="name" value="Name" class="width75" onfocus="clearValue(this, 'Name');" onblur="fillValue(this, 'Name');"/> </p> <p> <input type="text" name="email" value="E-mail" class="width75" onfocus="clearValue(this, 'E-mail');" onblur="fillValue(this, 'E-mail');"/> </p> <p> <input type="text" name="subject" value="Subject" class="width75" onfocus="clearValue(this, 'Subject');" onblur="fillValue(this, 'Subject');"/> </p> <p> <textarea name="message" rows="5" cols="80" onfocus="clearValue(this, 'Message');" onblur="fillValue(this, 'Message');">Message</textarea> </p> <p> <input type="submit" value="SEND" class="button" /> <input type="reset" value="RESET" class="button" /> </p> </form>
March 3, 200818 yr Author Hi guys...is there anyone out there willing to shed some light on this for me? Pweeeeeease?
March 3, 200818 yr Okay, well, the HTML part of your form looks okay... but you'll need PHP (or some other sever-side language) to process that form. HTML can't do that. Try this : http://www.jemjabella.co.uk/stuff/mail_form.php : instead.
March 3, 200818 yr You can also check and see if your host has a form action mail handler thingy (Bluehost does, for example), which makes things a lot easier and doesn't require any PHP knowledge. It looks something like this (but obv. with your host's details filled in): <form action="http://www.bluehost.com/bluemail" method="POST">
March 3, 200818 yr Depending on your server setup, most packages come with a CGI bin and a load of useful script. Alas, many don't support PHP. However, there's usually a FORMMAIL script in the CGI bin from Matts Scripts archive. Let us know more about your server details, and we'll guide you best. PHP is simple and quick, but CGI works perfectly well too. Also, it's more than possible to get a simple form sent via mailto, although there's no 'field required' control. But it makes sending a form simple, and sends literally a copy of all the form fields to email. That's 3 options so far available. But you *do* need to let us know what scripting is available to help any further.
March 6, 200818 yr Author Depending on your server setup, most packages come with a CGI bin and a load of useful script. Alas, many don't support PHP. However, there's usually a FORMMAIL script in the CGI bin from Matts Scripts archive. Let us know more about your server details, and we'll guide you best. PHP is simple and quick, but CGI works perfectly well too. Also, it's more than possible to get a simple form sent via mailto, although there's no 'field required' control. But it makes sending a form simple, and sends literally a copy of all the form fields to email. That's 3 options so far available. But you *do* need to let us know what scripting is available to help any further. Hi guys thanks for all your replies! Seige, my server is from 1&1 and running Linux. The admin panel has a lot of standard CGI options but they're not very aesthetically pleasing. The HTML of my form should be ok, I'm just stuck on the processing side! Any light you could shed will be greatly appreciated.
March 7, 200818 yr @Racheal I have tried that jamjam contact sheet and have uploaded it. The error message when i try send a message is: Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Inetpub\wwwroot\connect\contactform.php on line 49 Sorry, there was an error and your mail was not sent. Please find an alternative method of contacting the webmaster. and line 49 on my php form is if (mail($recipient,$subject,$message,$headers)) { is there a way to define the mail server? Any help would be much apprieciated Cheers
March 7, 200818 yr @Aled Mann It feels like you're looking for a quick and easy way to send an email from a form. Something like sendMyEmailNOW(); Sorry to say there's no such thing. While sending an email is a pretty straight forward idea it encompasses many aspects of server side languages that aren't so simple - functions variables etc. Either you could use some sort of pre made script / online service to create your form or you could take the long road. Start learning a scripting language such as php for example. I'm sure the 2nd option would benefit you in the future as knowledge is power moreover it wouldn't take long to begin making your mighty email script. I'm not trying to be negative or say you can't do it. There's just no simple answer. In terms of shedding light, processing forms follow these steps ( or similar ) -> Submit form -- This sends the form data back to the server -- In php we have a global var called $_POST that contains all your post data in an array. Can be accessed via $_POST['username'] for example -> Validation -- Check posted data is safe, not empty, and correct format -> Send the email -- Php has a built it mail function, but there are many methods to go about it. -- Personally I use phpmailer, it's a php class that sends emails nice and easy ( from a dev pov ) Apart from that there isn't much more I could say without actually teaching you PHP. Enjoy the rant
March 7, 200818 yr Ok i have dug a little deeper and think that i need to set my php.ini. I have created a file with the same name and added this into it SMTP = MYSMTPsmtp_port = 25 Then in my php form I have added this line: if (mail ini_set = "php.ini";($recipient,$subject,$message,$headers)) { instead of my old one: if (mail($recipient,$subject,$message,$headers)) { and still say's that it trying to connect to localhost. I'm totally new to php so i think that i have just not said the ini_set line correctly, any ideas? Cheers
March 7, 200818 yr @bobbymooreok By the looks of it you're using a windows server? In any case you shouldn't need to create a php.ini there should already be one. I also recommend using phpmailer, it handles this type of problem
March 7, 200818 yr I am indeed 2k3, IIS etc. Where is this php.ini located as we have multiple sites under the same root and only want to apply these settings to this site. Have hidden files shown ofc ^^.
March 7, 200818 yr @bobbymooreok My recommendation is to use the phpmailer class. It enables you to set the smtp address ( among other things ) on the fly. Other than that could try something with a .htaccess file as this acts similar to your php.ini config except it works at directory level.
March 11, 200818 yr Author OK..so here's the PHP script that goes alongside the HTML of this form, but I still can't get the bugger to work! Eeeeeeeee! <?php $name = $HTTP_POST_VARS['name']; $email = $HTTP_POST_VARS['email']; $subject = $HTTP_POST_VARS['subject']; $message = $HTTP_POST_VARS['message']; if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } elseif ($subject == "") { echo "<h4>No subject</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } elseif (mail($name,$email,$subject,$message)) { echo "<h4>Thank you for contacting us</h4>"; } else { echo "<h4>An error has occured. Please click back and try again or send an email to info@webexpress-uk.com</h4>"; } ?> Form HTML <form id="contact" action="form.php" method="post" onsubmit="return configForm(this);" style="position: relative; z-index: 1;"> <p> <input type="text" name="name" value="Name" class="width75" onfocus="clearValue(this, 'Name');" onblur="fillValue(this, 'Name');"/> </p> <p> <input type="text" name="email" value="E-mail" class="width75" onfocus="clearValue(this, 'E-mail');" onblur="fillValue(this, 'E-mail');"/> </p> <p> <input type="text" name="subject" value="Subject" class="width75" onfocus="clearValue(this, 'Subject');" onblur="fillValue(this, 'Subject');"/> </p> <p> <textarea name="message" rows="5" cols="80" onfocus="clearValue(this, 'Message');" onblur="fillValue(this, 'Message');">Message</textarea> </p> <p> <input type="submit" value="SEND" class="button" /> <input type="reset" value="RESET" class="button" /> </p> </form>
March 11, 200818 yr .. elseif (mail($name,$email,$subject,$message)) { .. The mail function is a bit wrong, http://nz2.php.net/manual/en/function.mail.php The mail function requires 3 parameters to function. To: This is the address the email is going TO, from FROM, the current $email variable in your script is the FROM address Subject: This is the subject of the email, how you've got it right now is correct Message: Again the message body, using the right method so far. So to rewrite your mail function $my_email = 'my_personal_address@mysite.com'; mail($my_email,$subject,$message); You will need to build up the message, containing their name, email, and message. For example $message = $name . $email . $message; This is the simplest idea, some formatting could be added. For example $message= ' Message from: '.$name."\n\n".' Address: '.$email."\n\n". $name .' wrote: '."\n\n".$message; This would give the equivalent formatting, Message from Warren Address: warrensemail@email.com Warren wrote: Hello Aled I like your hair cut. Have a nice day There can be more advancement but if we get this going we can see about them later EDIT: also change $HTTP_POST_VARS to $_POST $name = $_POST['name']; also, I like your website's design
March 11, 200818 yr Author Warren you are a god send! Thank you so much for your help!! OK...so here's what I now have... <?php $name = $_POST['name']; $email = $HTTP_POST_VARS['email']; $subject = $HTTP_POST_VARS['subject']; $message = $HTTP_POST_VARS['message']; if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } elseif ($subject == "") { echo "<h4>No subject</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } $my_email = 'info@webexpress-uk.com'; mail($my_email,$subject,$message); $message= ' Message from: '.$name."\n\n".' Address: '.$email."\n\n". $name .' wrote: '."\n\n".$message; echo "<h4>Thank you for contacting us</h4>"; } else { echo "<h4>An error has occured. Please click back and try again or send an email to info@webexpress-uk.com</h4>"; } ?> I uploaded it and tested the form and received the following error: Parse error: syntax error, unexpected '}' in /homepages/18/d229507269/htdocs/form.php on line 30 Thank you again for your help and keeping me sane!
March 12, 200818 yr Try this.. <?php $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { echo "<h4>Invalid email address</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } elseif ($subject == "") { echo "<h4>No subject</h4>"; echo "<a href='java script:history.back(1);'>Back</a>"; } else { $my_email = 'info@webexpress-uk.com'; $message = ' Message from: '.$name."\n\n".' Address: '.$email."\n\n". $name .' wrote: '."\n\n".$message; if (mail($my_email,$subject,$message)) { echo "<h4>Thank you for contacting us</h4>"; } else { echo "<h4>An error has occured. Please click back and try again or send an email to info@webexpress-uk.com</h4>"; } } ?>
March 12, 200818 yr Author Warren! You are an absolute genius. Thank you so much mate! Really!! If you ever need a DJ let me know (cos I ain't much cop with PHP lol!) I do have one teensy weensy last question though (you're gonna shoot me aren't you?) How do I redirect the sucessful send or error to a HTML page that looks the same only with an error message at the bottom? For example wbexpress-uk.com/contactsucess.html and wbexpress-uk.com/contacterror.html. I know how to code the pages, just not what to put in the PHP! *runs for the hills of Wales*
March 12, 200818 yr It's actually pretty easy. My advice isn't to have 2 separate html pages but instead use some php to decide the output. Using a page with your current template, you could write something like this: ( This isn't an exact example, and I haven't tested it ) This code goes at the very top of the page ------------------------------------------------ <?php $showForm = 1; if($_POST['contactForm']) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) { $error = "<h4>Invalid email address</h4>"; $error .= "<a href='java script:history.back(1);'>Back</a>"; } elseif ($subject == "") { $error = "<h4>No subject</h4>"; $error .= "<a href='java script:history.back(1);'>Back</a>"; } else { $my_email = 'info@webexpress-uk.com'; $message = ' Message from: '.$name."\n\n".' Address: '.$email."\n\n". $name .' wrote: '."\n\n".$message; if (mail($my_email,$subject,$message)) { $showForm = 0; $success .= "<h4>Thank you for contacting us</h4>"; } else { $error = "<h4>An error has occured. Please click back and try again or send an email to info@webexpress-uk.com</h4>"; } } } ?> ------------------------------------------------ //All your html, head, body etc etc This goes in the area your form is ment to display ------------------------------------------------ <?php //Code here determines if we display the form or not echo $success if($showForm == 1) { echo $error; ?> <form id="contact" action="contact.php" method="post" onsubmit="return configForm(this);" style="position: relative; z-index: 1;"> <p> <input type="text" name="name" value="Name" class="width75" onfocus="clearValue(this, 'Name');" onblur="fillValue(this, 'Name');"/> </p> <p> <input type="text" name="email" value="E-mail" class="width75" onfocus="clearValue(this, 'E-mail');" onblur="fillValue(this, 'E-mail');"/> </p> <p> <input type="text" name="subject" value="Subject" class="width75" onfocus="clearValue(this, 'Subject');" onblur="fillValue(this, 'Subject');"/> </p> <p> <textarea name="message" rows="5" cols="80" onfocus="clearValue(this, 'Message');" onblur="fillValue(this, 'Message');">Message</textarea> </p> <p> <input type="submit" name="contactForm" value="SEND" class="button" /> <input type="reset" value="RESET" class="button" /> </p> </form> <?php } ?> //Rest of your template html ------------------------------------------------ Since you're using PHP and HTML is the same page, you'll need to rename it to something.php, then the form's action="" will need to match the filename. See how it goes Also your error messages might need to be updated, as you wont need to "go back" anymore, seeing as you'll still be on the same page.
Create an account or sign in to comment