Today I will show you how to build on your Web Design skills and create a simple newsletter sign up form.
After the form has been filled in we will send them to a php page that will process the data and send us an email .
First we have to start with the Form itself.
Here is a basic form asking for Name and Email address.
<form id=”form1″ name=”form1″ method=”post” action=”Submit.php”>
<table>
<tr>
<td>Name</td>
<td><input type=”text” name=”name” id=”name” />
</td>
</tr>
<tr>
<td>Email</td>
<td> <input type=”text” name=”email” id=”email” />
</td>
</tr>
<tr>
<td> </td>
<td> <input type=”submit” name=”button” id=”button” value=”Submit” />
<td>
</tr>
</table>
</form>
We are going to post the data through the server to our submit.php page.
This is where we put the script that is used to build the message and email the information over.
Create a file called Submit.php, and use the following code.
To tell the server that we are going to be using php we start with the tag “<?php” and close with “?>”
Right, lets get that data from the form and create the email message.
A few quick basics…
$_POST[‘name’]; //this is the vale of the name field in the form.
$_POST[‘email]; //this is the vale of the email field in the form.
Lets set the message up.
$message = ‘You have a received a new Newsletter Sign up customer.\n”;
$message .= ‘The details are Below. \n”;
$message .= ‘Name: ’ ;
$message .= $_POST[‘name’];
$message .= “\n”;
$message .= ‘Email’;
$message .= $_POST[‘email];
The full stop before the = sign says $message = itself + $message. This builds the email structure.(the ‘\n’ is a line break)
Lets get this emailed over to us.
mail(‘test@example.com’, ‘My Subject’, $message);
And that is it!
Here is the code for Submit.php in full..
<?php
$message = ‘You have a received a new Newsletter Sign up customer.\n”;
$message .= ‘The details are Below. \n”;
$message .= ‘Name: ’ ;
$message .= $_POST[‘name’];
$message .= “\n”;
$message .= ‘Email’;
$message .= $_POST[‘email];
mail(‘test@example.com’, ‘My Subject’, $message);
?>
Related posts:



I am looking for a form like on myspace where you can sign up and create an account and all that…
Comment by Samantha — November 14, 2008 @ 4:48 am
Thanks for the article I will have a go.
Comment by sam — November 27, 2008 @ 5:21 pm