Sorry about the delay.
Anyway, here it is. It takes two fields. Name and email.
a. The form inside a table below goes in the page where you want people to submit the info. You can change the look anyway you choose, just make sure the form and the field names inside the form are unchanged.
<form name="form" method="post" action="./mailsubmitted.php">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="3" bordercolor="#CCCCCC">
<tr>
<td align="right" valign="middle" bgcolor="#CCCCCC"><p>Name:</p></td>
<td align="left" valign="middle" bgcolor="dddddd">
<p>
<input name="name" type="text" class="input" id="contactname2" size="10" maxlength="25">
</p> </td>
</tr>
<tr>
<td align="right" valign="middle" bgcolor="#CCCCCC">
<p>Email:</p></td>
<td align="left" valign="middle" bgcolor="dddddd">
<p>
<input name="email" type="text" class="input" id="email" size="10" maxlength="25">
* </p> </td>
</tr>
<tr>
<td width="65%" align="left" valign="middle">Please enter your name and email address
to get notified when the site is updated. </td>
<td align="center" valign="middle"><div align="center">
<input type="submit" name="Submit" value="Submit" class="button">
</div></td>
</tr>
</table>
<p> </p>
</form>
- <form name="form" method="post" action="./mailsubmitted.php">
- <table width="300" border="0" align="center" cellpadding="0" cellspacing="3" bordercolor="#CCCCCC">
- <tr>
- <td align="right" valign="middle" bgcolor="#CCCCCC"><p>Name:</p></td>
- <td align="left" valign="middle" bgcolor="dddddd">
- <p>
- <input name="name" type="text" class="input" id="contactname2" size="10" maxlength="25">
- </p> </td>
- </tr>
- <tr>
- <td align="right" valign="middle" bgcolor="#CCCCCC">
- <p>Email:</p></td>
- <td align="left" valign="middle" bgcolor="dddddd">
- <p>
- <input name="email" type="text" class="input" id="email" size="10" maxlength="25">
- * </p> </td>
- </tr>
- <tr>
- <td width="65%" align="left" valign="middle">Please enter your name and email address
- to get notified when the site is updated. </td>
- <td align="center" valign="middle"><div align="center">
- <input type="submit" name="Submit" value="Submit" class="button">
- </div></td>
- </tr>
- </table>
- <p> </p>
- </form>
b. The php code below goes to a page named mailsubmitted.php . This is where the user is redirected after submission. Create the layout anyway you choose according to your site theme. The php code below goes where you want to show the user the message about a successful submission or invalid email address. The name field is optional. The php code only checks for a valid email address in the form
someone@somehost.com . If invalid the user can go back and enter the address again.
<?php
$what = true;
$chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
if (!$chkemail) {
echo "Please enter a valid email address in the form someone@somehost.com<br>
Hit the browser's back button to go back and enter a valid email address.<br>";
$what = false;
}
$formatted = $name." : ".$email;
if ($what == true)
{
$fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
fwrite($fp, "$formatted \r\n");
fclose($fp);
echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
}
?>
- <?php
-
- $what = true;
-
- $chkemail = ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $email);
-
- if (!$chkemail) {
-
- echo "Please enter a valid email address in the form someone@somehost.com<br>
-
- Hit the browser's back button to go back and enter a valid email address.<br>";
-
- $what = false;
-
- }
-
- $formatted = $name." : ".$email;
-
- if ($what == true)
-
- {
-
- $fp = fopen("./maildata.txt", "a");//change the file name maildata.txt to somethingelse.txt for lil security.
-
- if (!$fp) die ("Sorry, Cannot open file to write Try Later.");
-
- fwrite($fp, "$formatted \r\n");
-
- fclose($fp);
-
- echo "Thank you for entering your email address. We will get back to you as soon as we launch our new site.";
-
- }
-
- ?>
c. Before you test it, make a txt file named maildata.txt or somethingelse.txt that you specify above in the code. As it is all files must be in the same directory. CHMOD the file permission to world writable. 766 or 777 whatever works in your server.
d. Now try and submit. To view the data download and open the text file. It should output something like this:
Let me know if there is a problem. Also if you want the information to be formatted in any other way you find convenient, we can change it.
Web development company : quantumcloud
Web design company : web.com.bd