Web Hosting Talk







View Full Version : Question about using a form to send info!?!?


build-a-host
07-24-2008, 07:35 AM
Hello all,

I am new to coding, and I am trying to edit a script I just bought. It is a domain appraisal script, but it does not have the option to offer free appraisals, it only has the option to submit payment to PayPal or StormPay.

I have managed to change the code around enough to where it is not directing to PayPal anymore, but now when I click submit, Outlook Express pops up with my email address like a regular mailto: function.

I read at www.w3schools.com/html/html_forms.asp (http://www.w3schools.com/html/html_forms.asp) about creating forms, but each one I have tried from there does the same thing, or it brings up an internet connection wizard which attemots to direct me through setting up an outlook box!

You can see the page I am talking about at www.drcoms.com/appraisal (http://www.drcoms.com/appraisal) . I want it to be setup so that the user enters his name, email, and domain name, and it sends me all the info. Can anyone tell me how I can go about doing this? HEre is what I have right now for the form code::


<form name="input" action="MAILTO:admin@afreewebhost.com (admin@afreewebhost.com)"
method="get">
Name:
<input type="text" name="name"><br>
Email Address:
<input type="text" name="email"><br>
Domain Name:
<input type="text" name="domainame"><br>
<input type="submit" value="Submit">
</form>



I'm sure I have it setup wrong and it's probably something very easy that I need to change, but I have tried many different ways, and it does the same thing evertime, so now I turn to you guys, the pros, for help!

Any help would ne GREATLY appreciated!

webcertain
07-24-2008, 08:17 AM
eh ?

your action is a mailto link, of course its going to come up with a mail sending window, as that's what you've set it to do!

What you haven't got, is a page to handle the form into and send it to you, you'd have to create that in ASP (assuming your hosting is asp.

Web forms basically work like this

1. Frontend form code, POSTS data to 2nd page ie,

<form action="formhandler.php" method="POST">
form bits
</form>

2. the formhandler page grabs that data, and then emails it off.

build-a-host
07-24-2008, 08:20 AM
Thanks, I got it all worked out. For anyone that might have this question in the future, here is the code for a form to send info to your email addy:


<?php
if($_POST) {
//Check data
if(!$_POST['VisitorName'] || !$_POST['VisitorEmail'] || !$_POST['VisitorDomains']) {
echo "Please fill in all the fields!";
}
else {
//Construct message
$to = "youremail@yourwebsite.com"; # Your email here
$from = "Mywebsite@domain.com"; # Who is it from
$subject = "Free Domain Appraisal"; # The email subject
$headers = "From: ".$from."\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: text/html; charset=utf-8\r\n" .
"Content-Transfer-Encoding: 8bit\r\n\r\n";
$message = "Name: ". $_POST['VisitorName'] ." <br /> Email: ". $_POST['VisitorEmail'] ." <br /> Domains: ". $_POST['VisitorDomains'];
mail($to, $subject, $message, $headers);
echo "Email sent!";
}
}
?>
<form
action=""
method="POST"
enctype="multipart/form-data"
name="AppraisalRequestForm">
Your Name:<br>
<input type="text" size="20" name="VisitorName"><br><br>
Your Email:<br>
<input type="text" size="20" name="VisitorEmail"><br><br>
Your Domains:<br>
<textarea name="VisitorDomains" rows="4" cols="20">
</textarea><br><br>
<input type="submit" value="Send Request For Domain Appraisal">
</form>

biffer
07-25-2008, 01:46 AM
This code is a start, but you need to add some input filters, or someone is going to use your form as a spam relay. I will defer to someone who is more PHP savvy, but I believe you want to at least pass the user input through the htmlentites() function.