Here is a simple Form Mail script. It can be used on your website for people sending you messages, rather than using an email link. The script provides a form with name, email address, and message. It validates that all three fields are completed and that the email address format is valid. It also provides some protection against mail bombing by only allowing 3 messages to be sent from a single browser session. You can easily modify the script to fit the theme of your site, or change the form. The example below uses the script name mail.php (see the form action=), so put the script in a file by that name.
- - Start Script Here - -
- - End Script Here - -
Note that the mail bomb protection feature uses a session variable and will not function if cookies are blocked.
In summary, the only things you need to do are:
1) Change the value mail@yourdomain.com to your email address - in the mail() function
2) Change the value yourdomain.com to your domain name - in the mail() function
3) Put the script in a file called mail.php
4) Upload and enter mail.php in your browser
- - Start Script Here - -
<?phpif (isset($_POST['send'])) {
session_start();
$name = $_POST['name'];
$email = $_POST['email'];
$content = $_POST['content'];
if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i", $email)) $alert = "You have entered an invalid email address.";
if ($name == "" OR $email == "" OR $content == "") $alert = "To send a message, please complete all 3 fields.";
if ($_SESSION['mail_count'] >= "3") $alert = "Only 3 messages can be sent per session.";
if (!$alert) {
if (!isset($_SESSION['mail_count'])) $_SESSION['mail_count'] = 0;
$_SESSION['mail_count']++;
$message .= "Name as follows:\n\n";
$message .= "$name\n\n";
$message .= "Email address as follows:\n\n";
$message .= "$email\n\n";
$message .= "Message as follows:\n\n";
$message .= "$content\n\n";
mail("mail@yourdomain.com", "yourdomain.com Message" , "$message", "From: Website <>");
$name = "";
$email = "";
$content = "";
$alert = "Your message has been sent.";
}
}?><html>
<head>
</head>
<body>
<table align="center" cellspacing="0" cellpadding="5" style="height: 450px; width: 500px; margin-top: 50; border: solid 1px black;">
<tr><td align="center"><form method="post" action="mail.php"><br>
Send me a message<br><br>
your name<br><input type=text style="width: 330px;" name="name" value="<?=$name?>" maxlength=50><br><br>
your email address<br><input type=text style="width: 330px;" name="email" value="<?=$email?>" maxlength=50><br><br>
your message<br><textarea name="content" rows="6" cols="40"><?=$content?></textarea>
<br><br>
<input type="submit" name="send" value="submit">
</form></td></tr>
</table>
<?phpif ($alert) {
echo "<script type='text/javascript'>
<!--
alert ('$alert');
//-->
</script>";
}?></body></html>- - End Script Here - -
Note that the mail bomb protection feature uses a session variable and will not function if cookies are blocked.
In summary, the only things you need to do are:
1) Change the value mail@yourdomain.com to your email address - in the mail() function
2) Change the value yourdomain.com to your domain name - in the mail() function
3) Put the script in a file called mail.php
4) Upload and enter mail.php in your browser
Comments
Post a Comment