View Full Version : PHP Form Script for mail

10-08-2007, 05:14 PM

Please help, I downloaded the form mail script below and got stuck. Firstly do I separate the script so that everything before the <html> gets pasted on a blank text document and saved as fm.php which then gets uploaded to cgi-bin. Secondly do I paste all of the stuff in between the <html> tags and save it as an html page and upload?

I guess I am sounding rather daft but I donít know the first thing so any help on how I can take what is claimed to be a working script, but does not come with a manual and configure it so that the website has a simple form mail.


// modify the three lines below
$htmlMail = "no"; // "yes" to send html mail - otherwise sends text mail
$emailAddress = "mail@domain.com"; // your email address
$thankyouPage = ""; // leave empty to return to the form after a message has been sent - put in a url (or relative page) to go to a Thank You page
// modify the three lines above
if (isset($_POST['send']) AND isset($_SESSION['mail_count'])) {
if (!preg_match("(^[-\w\.]+@([-a-z0-9]+\.)+[a-z]{2,4}$)i", $_POST['email'])) $alert = "You have entered an invalid email address.";
if ($_SESSION['mail_count'] >= "3") $alert = "Only 3 messages can be sent per session.";
if (empty($alert)) {
if (!get_magic_quotes_gpc()) foreach ($_POST as $key=>$value) $_POST[$key] = addslashes($_POST[$key]);
foreach ($_POST as $key=>$value) $_POST[$key] = wordwrap($_POST[$key],65);
if ($htmlMail == "yes") {
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<table border='1'>";
foreach ($_POST as $key => $value) if (!preg_match("(^send)", $key)) $message .="<tr><td><b>$key</b></td><td>$value</td></tr>";
$message .= "</table>";
} else {
foreach ($_POST as $key => $value) if (!preg_match("(^send)", $key)) $message .= $key . "->\n " . $value . "\n\n";
$subject = $_SERVER['HTTP_HOST'] . " Message";
$headers .= "From: <" . $_POST['email'] . ">\r\n";
if (!empty($thankyouPage)) {
header('location: ' . $thankyouPage);
$alert = "Your message has been sent.";
if (!isset($_SESSION['mail_count'])) $_SESSION['mail_count'] = 0;
<form method="post" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>">
<div style="text-align: center; height: 450px; width: 500px; margin-top: 50; border: solid 1px black;">
Send me a message<br><br>
your name<br><input type="text" style="width: 330px;" name="name" value="<?php echo $_POST['name']; ?>" maxlength="50"><br><br>
your email address<br><input type="text" style="width: 330px;" name="email" value="<?php echo $_POST['email']; ?>" maxlength="50"><br><br>
your message<br><textarea name="content" style="width: 330px; height: 100px;" rows="6" cols="80"><?php echo $_POST['content']; ?></textarea>
<input type="submit" name="send" value="submit">
<?php if (isset($alert)) echo "<script type='text/javascript'>alert('$alert');</script>"; ?>

10-08-2007, 05:34 PM
You just put it all together in one php file and upload it just as you would upload a html file

10-09-2007, 01:26 AM
Is your mail form not working?