Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Contact Form dilemma

Featured Replies

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! :D

 

<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!!

  • Author

Sh...! This was meant to be posted in the How do I do that forum, sorry!!

 

Way to go AL!! :rolleyes:

 

I would still like an answer though pretty please! Thank you! :D

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. :(

  • Author

Hey, ok thanks Rachel!

 

Next question...how do I fix it? LOL! :D

Sh...! This was meant to be posted in the How do I do that forum, sorry!!

 

Way to go AL!! :rolleyes:

 

I would still like an answer though pretty please! Thank you! :D

 

 

 

No answer from me, but thread is now where you wanted it :D

  • 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>

  • Author

Hi guys...is there anyone out there willing to shed some light on this for me? Pweeeeeease? :D

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">

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.

  • 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.

@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

@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 :D

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 = MYSMTP

smtp_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

@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 :D

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 ^^.

@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.

  • 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>

 ..
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 :D

 

EDIT: also change $HTTP_POST_VARS to $_POST

$name = $_POST['name'];

 

also, I like your website's design :D

  • 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! :D

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>";

}

}

?>

  • 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* :lol:

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.