Click to See Complete Forum and Search --> : ASP? MySQL? IIS? I just wanna build a form...


Amadeo
10-23-2005, 05:05 PM
Oh No! Another newbie....

Yes, everyone, I'm a newbie... but a bright one!

I need help with something that's very simple, I'm sure. I want to build a form that submits all of the entries to an e-mail address without calling the default mail client on the client side. I'll figure out sending the data to a DB later....

After spending the last 20 hours reading miles and miles of code and 'tutorials - yeah right, if that's what they were I wouldn't be here asking for help, I'd already have learned it by now!' I've only figured out a few things.

I know how to build the form page.
I don't know how to send the data to my e-mail address.

If one of you wizards wouldn't mind helping me, I'd really appreciate it!

Respectfully,

Amadeo

NogDog
10-23-2005, 05:20 PM
If your web host supports PHP, I know how to do it. :)

MstrBob
10-23-2005, 05:24 PM
Yes, it depends on what language your host supports. I suppose the most common is PHP, but there are many others.

Fortunately, form handling is one of the simplest tasks to perform with server side languages.

Amadeo
10-23-2005, 06:52 PM
Thank you! Thank you!

It sure does support PHP!

MstrBob
10-23-2005, 07:18 PM
Alright, well, here's a basic Form handler to send to email. Create a php page, and name it whatever you like. Let's just say 'email.php'. So this would be email.php:


<?PHP
$to = 'youremail@address.com'; // This is the email address to send results to
$subject = 'Form Results'; // This is the Email's subject line
if(!empty($_POST))
{
$results='--------------------------'."\n".'Form received on '.date('F j, Y')."\n\n";
foreach($_POST as $key => $value)
{
$results.=$key.': '.htmlentities(stripslashes($value))."\n\n";
}
if(@mail($to, $subject, $results))
{
echo("You're form results have been successfully submitted.");
}
} else {
header('Location: '.$_SERVER['HTTP_REFERER']);
}
?>



The $to variable is the email address we want to send the email to. The $subject variable is the subject line of the email. So here's the breakdown of what's going on in the script.

if(!empty($_POST))
This if/else statement is checking to see if a form was submitted. If it is, we process it, if not, we send the user back where they came from - usually the form page (the one with HTML).

$results='--------------------------'."\n".'Form received on '.date('F j, Y')."\n\n";
The $results variable is the body of the email, it's also where we'll store all the form's variables. The date() function is there to tell you the date the form was sent.

foreach($_POST as $key => $value)
This is a foreach statement. The $_POST array contains each form element and the user-supplied value. The foreach statement goes through each element in the array, one by one.

$results.=$key.': '.htmlentities(stripslashes($value))."\n\n";
Here we are adding the name of each form element, and the value the user put in. We are adding this to the $result variable, which you remember is the body of our email. the htmlentities() and stripslashes() functions keeps the users from inserting anything harmful.

if(@mail($to, $subject, $results))
This is our mail function, inside an if statement. The '@' symbol in front keeps the server from sending back any nasty errors that may result if email for whatever reason is available. You might want to remove it if you want, but I don't like for users to see PHP errors. Its your choice really. The if statement checks to see if the email was sent. If it was, we tell them so. You could also add an else to this to alert the user of an error.

header('Location: '.$_SERVER['HTTP_REFERER']);
This redirects users to where they came from if they didn't fill out the form.


Now this is a VERY barebones example. You'll probably want to expand this with bits, like telling the user if the email wasn't sent, or using if/else statements to require that certain form elements are filled out. Don't forget, for your HTML form, set the action="" to this php page. So if you named this page email.php, you'd have:

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

Amadeo
10-23-2005, 09:07 PM
Uh oh....

Turns out my particular account is Windows based and only runs ASP & CDONTS

If I had the Linux account it would run PHP

Think there's any hope?

MstrBob
10-23-2005, 09:25 PM
Sure, this can also be done in ASP. This thread has some good information:

http://www.webdeveloper.com/forum/showthread.php?t=39991

Also, try posting your question in the ASP forum.

Amadeo
10-24-2005, 07:45 PM
Thanks! I'll check it out right now....

I also bought asp.net for dummies, it won't arrive for a while - I hate it if I have to buy one of those books - think it's any good?

Respectfully, Amadeo

Amadeo
10-24-2005, 08:19 PM
How do I find out about my smpt server? Contact my hosting company, I assume.

Also, should I move this conversation to the ASP forum?

Thanks for all your help!

Amadeo

David Harrison
10-25-2005, 07:31 PM
I've moved it to the ASP forum for you.

Basically, the SMTPserver variable is just asking for the IP address of your hosts mail server. I don't know about Godaddy, but most hosts have some sort of knowledge base or support forum that will most likely tell you what it is.

Also there's a typo in the script that I seemed to have made many times over, oops. It's SMTP not SMPT. :o

Amadeo
10-29-2005, 03:29 PM
Ok, so the machines are winning.....

I'd throw the whole project out the window this instant, however I love a challenge!

I'm hosted at GoDaddy.com. I bought ASP.net for Dummies. I've copied and pasted (and customized) miles of script from the kid on the corner to the gurus on Microsoft, and nothinig works.

GoDaddy is great, I've called them several times and they've always been helpful to an extent but not enough to achieve my goal (they do hosting, not programming).

I'm 'bout ready to switch over to PHP. Should I or should I not?

I just want to build a friggiin' form that will take the info that a user puts in and send it to an e-mail account.

Later, I want that info to go into a database that can then be accessed by the owner of the site.

Should I just jump over and do the database thing and get this agony over with? Should I start with simple e-mail? Should I slit my wrists and forget the whole thing altogether?

Please help.....

Respecfully,

Amadeo

JoeyD
10-31-2005, 07:23 AM
Not sure if godaddy has aspmail installed on thier server but this is how I send mail using the aspMail component:

<%
function mailer(message, mailTo)
Dim mail
set mail = Server.CreateObject("Persits.MailSender")
mail.host = smtp
mail.port = port
mail.from = "Fromme@domian.com"
mail.fromname = "From Me"
mail.AddAddress MailTo 'passed to this function
mail.addbcc "bbcme@domain.com"
mail.subject = "email subject"
mail.body = message ' email message
mail.IsHTML = True
On Error Resume Next
Mail.Send
end function
%>
Hope this helps

David Harrison
10-31-2005, 08:12 AM
Amadeo, you said that you're working with ASP.net, ASP.net will only work on godaddy's hosting if you have either the Deluxe or Premium plans.

You should also note that ASP is not the same as ASP.net, and if you are working with ASP.net, it may be worth heading over to the .NET forum and making a new thread there.

Amadeo
10-31-2005, 09:07 PM
Thank you everyone!

I have a GoDaddy deluxe plan that supports asp.net.

How do I move this thread to the asp.net forum?

Cheers,

Amadeo

David Harrison
11-01-2005, 03:47 AM
At this point it might be better to just create a new one, this one already has a lot of replies and wouldn't get much interest.