...

View Full Version : Sending a form to an email address - please help :)



katef
06-02-2009, 10:51 AM
Hi all,

I'm trying to make a 'contact us' page for a website and want a form that allows the user to input their name, email address, and comment then send it to my hotmail account using a submit button. I've tried various things but it doesn't appear to be working. I've visited other forums and the general consensous is that it can be done fairly simply without the use of php etc, but I've yet to find anything that works. I'm reasonably new to programming so the simpler the better at the moment

Thank you in advance

Kate

brazenskies
06-02-2009, 10:54 AM
Do you know what web server you are using?

frankle
06-02-2009, 11:18 AM
Hi all,

I'm trying to make a 'contact us' page for a website and want a form that allows the user to input their name, email address, and comment then send it to my hotmail account using a submit button. I've tried various things but it doesn't appear to be working. I've visited other forums and the general consensous is that it can be done fairly simply without the use of php etc, but I've yet to find anything that works. I'm reasonably new to programming so the simpler the better at the moment

Thank you in advance

Kate

Are you looking for something like the one below:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Contact details</title>
</head>

<body>
<form action="mailto:emailid@gmail.com" method="post" enctype="text/plain" >
Name:
<input type="text" name="Name" />
Email:
<input type="text" name="Email" />
Comments:
<textarea name="Comments"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>


But this is not recommended. The best is to use any server side script like perl or php. Its simple and systematic.


Regards,

noneforit
06-02-2009, 12:41 PM
It can be done without PHP as Frankle says above but i would reccomend using PHP if the web server supports it. It would only need a few lines of PHP code to work

noneforit
06-02-2009, 12:52 PM
Right.....

Copy the PHP code below into notepad and save it as something like form.php. Make sure you edit the $webmaster variable with your own email address and change the thanks.html to a page on your site.


<?php

/* Subject and Email Variables */

$emailsubject = 'Contact Form';
$webMaster = 'something@example.com';

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$body = <<<EOT
Name: $name
Email: $email
Message: $message
EOT;

$headers = "From: $email\r\n";
$headers .= "Content=type: text/html\r\n";

/* Emailing the Form */

mail($webMaster, $emailsubject, $body, $headers);

/* Directing the User to the Webpage thanks.html */

header('Location: thanks.html');
?>

Then copy the HTML code below into your contact page. May need to edit the action="contactform.php" if you called the php document above anything other than contactform.



<form name="contactform" method="post" action="contactform.php">
<p align="center">&nbsp;</p>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#A0AFCB" width="100%">
<tr>
<td width="50%" align="center">Name:<p>&nbsp;</td>
<td width="50%" align="center">
<input type="text" name="name" size="25"><p>&nbsp;</td>
</tr>
<tr>
<td width="50%" align="center">Email Address:</td>
<td width="50%" align="center">
<input type="text" name="email" size="25"></td>
</tr>
</table>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">Message:</p>
<p align="center">&nbsp;</p>
<p align="center"><textarea rows="12" name="message" cols="38"></textarea></p>
<p align="center">&nbsp;</p>
<p align="center"><input type="submit" value="Submit" name="B1">&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="Reset" name="B2"></p>
</form>


Upload both to the webserver in the same folder, go to the contact page, fill it in and click submit. This should email the form content to yourself



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum