View Full Version : PHP Mailform
Steveo31
February 9th, 2004, 01:11 AM
I have a HTML page with a drop down menu, and a textarea. I am trying to find a way to get the page, once submitted, to upload the variables to an external .php page, and from there it will mail using the mail() function.
I think this is right:
<form name="form1" method="post" action="mailform.php">
I'm pretty noobish when it comes to all this, so please, bear with me. Would I have to have some sort of $_POST or somethin?
If I didn't explain well enough, let me know :)
ZYV
February 9th, 2004, 09:26 AM
Hi,
Well... it should be something like this:
$PG["support_mail"] = "you@domain.net";
$PG["support_name"] = "Your name";
$name = trim(safestrip($_POST["name"]));
$email = trim(safestrip($_POST["email"]));
$subject = trim(safestrip($_POST["subject"]));
$message = trim(safestrip($_POST["message"]));
// ........
// Check if user has filled in the form completely
if ( is_email($email) and (!empty($subject)) and (!empty($message)) and (!empty($name)) ) {
$mail_to = $PG["support_mail"];
$mail_to_name = $PG["support_name"];
mail ($mail_to, $subject, $message, "From: ".$name." <".$email.">\r\nTo: ".$mail_to_name." <".$mail_to.">");
} else {
if (isset($_POST["submit"]))
$error_message = "Fill!!!";
else
$error_message = "";
//. . . .. . . .. . . . ... ... .......
echo $error_message;
?>
<form action="./" method=post>
<table border=0>
<tr>
<td>Your name: </td>
<td><input type=text name=name size=40 value=''></td>
</tr>
<tr>
<td>Your e-mail: </td>
<td><input type=text name=email size=40 value=''></td>
</tr>
<tr>
<td>Please specify: </td>
<td><input type=text name=subject size=40 value=''></td>
</tr>
<tr>
<td>Your message:<br></td>
<td><textarea name=message rows=10 cols=40></textarea></td>
</tr>
<tr><td colspan=2></td></tr>
<tr><td colspan=2 align=right><input type=submit name=submit value='Send the message'></td></tr>
</table>
</form>
<?php
}
// Check if $email is a quasy-valid e-mail
function is_email($email) {
$ret = false;
if ( function_exists("preg_match") &&
preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $email)
)
$ret = true;
elseif (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$", $email))
$ret = true;
return $ret;
}
// If running with magic_quotes_gpc (get/post/cookie) set
// in php.ini, we will need to strip slashes from every
// field we receive from a get/post operation.
function safestrip($str) {
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return $str;
}
That is not a complete solution! You'll need to change it so it suits your needs and polish out bugs. Please be attentive and test your script carefully. If you leave a hole there is a big chance that spammers will break in. E.g. never take the destination email from the form field.
HTH,
Z.
Steveo31
February 9th, 2004, 10:34 AM
Ahh some of that makes sense. Some I still need to learn, but eh. I don't have anything else to do with my time ;)
Thanks for your time Z.
-Steve
vBulletin v3.0.5, Copyright ©2000-2008, Jelsoft Enterprises Ltd.