Support Forums
Submit Button - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Webmaster Support (https://www.supportforums.net/forumdisplay.php?fid=36)
+---- Forum: Website Development (https://www.supportforums.net/forumdisplay.php?fid=43)
+---- Thread: Submit Button (/showthread.php?tid=13236)



Submit Button - ElephantShoe - 10-27-2010

Alright, so I made (copy and pasted) a Submit / Suggestion box for my website but I have no idea how .asp works. How would I receive the information that a user types in the box?
Here's the code:
Code:
<form name="input" action="html_form_action.asp" method="get">
Suggestions:<br> <input type="text" name="user" /><br>
<input type="submit" value="Submit" />
</form>

If not, does anyone have a simple form mail script?


RE: Submit Button - Brandon - 10-27-2010

Yeah,
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Andrey's Email form</title>
</head>
<body>

<form method="post" action="sendemail.php">

<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input type="text" name="visitor" size="35" />
<br />
Your Email:<br />
<input type="text" name="visitormail" size="35" />
<br /> <br />
<br />
Mail Message:
<br />
<textarea name="notes" rows="4" cols="40"></textarea>
<br />
<input type="submit" value="Send!" />
<br />
</form>

</body>
</html>

That's the contact form you want to use, for example "Contactus.php" or whatever.

This is sendmail.php, the script itself.



Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>


<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a") ;

$subject = $text;

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Message: $notes \n
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail("claw@asdf.com", $subject, $message, $from);

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />

Attention: <?php echo Andrey ?>
<br />
Message:<br />
<?php $notesout = str_replace("\r", "<br/>", $notes);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="contact.php"> Next Page </a>
</p>

</body>
</html>

It's rather basic and self explanatory. You can also obviously tell where to edit and customize it as you see. It's good to learn how it works too Smile

EDIT: Oh, i'll also give you a small explanation. It basically just sends the information the user types in via POST and then the sendmail.php uses the actual code. Contact.php is basically the input values only.


In contact.php we have:


<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


Your Name: <br />
<input type="text" name="visitor" size="35" />
<br />

This will be just an example. Then, that creates the form to be named "visitor" as a variable like situation. When it goes into sendmail.php, it'll use that to generate the email using the "visitor" variable defined in sendmail as "$visitor = $_POST['visitor']; ".

Simple, right? Big Grin

The extra code:

'<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>'

Is to get the users IP information, etc. It's not always necessary but useful.


Also, I just made it for a friend so you'll want to customize a lot of it to your own uses obviously. It's in PHP too, not ASP. I wouldn't know how this works in ASP exactly anymore.

Enjoy
Brandon


RE: Submit Button - ElephantShoe - 10-28-2010

Thanks a lot for this! Works perfectly. :]


RE: Submit Button - Malmoc - 11-10-2010

Lawl .. i use that script Thanks!