PDA

View Full Version : form action, what's the best bid


kaattis
02-22-2004, 01:55 AM
I'm making a form for a friend, and she wants the replies be e-mailed to her. I used:

<form method="POST" action="mailto:name@somewhere.com?body=" encrypt="text/plain">

But when the form is sent, the response is not in the body of the e-mail, but attached as a .ATT file. Is there a way to make the reply appear in the body of the e-mail?

Is there any other ways to go about submitting this form, other than mailto action(i realized that if the person submitting the form doesn't have outlook account set up, it may cause a problem)?

missing-score
02-22-2004, 02:04 AM
Hi, welcome to the forums.

To do what you are asking the best method is to use some form of server-side program that will take what the user inputs and send it in an e-mail. This will allow the information to be sent regardless of whether the user has outlook or not, and it will also get sent as the body of the e-mail.

You may want to look into PHP, ASP or CGI.

If you dont have these enabled there isnt really any other way.

Matt

kaattis
02-22-2004, 02:26 AM
I kind of suspected that......I have PHP enabled, I also have a PHP book (i'm a beginner), I tried to look for code that might do something like that, but couldn't find anything, the closest it gets is making form using php functions, but doesn't have anything on how to send the submitted info to an e-mail address. Do you have any suggestions of resources where I can find examples like that? Thanks.

kat.

oracleguy
02-22-2004, 02:34 AM
You need to use php's mail() function to send mail. See: http://us2.php.net/manual/en/function.mail.php

I personally it like better than using CDONTS in ASP. However the easiest mail implementation I've used is in, I hate to say, ColdFusion. Not that it really matters a whole bunch.

missing-score
02-22-2004, 02:40 AM
Luckily for you im a PHP programmer :p

This topic has been covered many times, but here it is again:

Say you have this form:

<p>
<form action="email.php" method="post">
Name: <input type="text" name="name" /><br />
Email: <input type="text" name="mail" /><br />
<input type="submit" value="Send" />
</form>
</p>

Of course, you could add more fields but this is an example. As you can see the action of the form is "email.php", so this is what email.php should contain:

<?php

$emailmessage = 'A new registration on your site\r\n\r\n';

/* This part here, called a foreach loop, will automatically
get all the post data sent in the form and make it into
a nice format for the e-mail */

foreach($_POST as $key => $value){
$emailmessage .= $key . ": ". $value . "\r\n";
}

$emailmessage = '\r\nEnd of Email\r\n";

$to = "adminemail@website.com";
$subject = "New Registration";
$headers = "From: register@website.com\r\n";

if(mail($to, $subject, $emailmessage, $headers)){
echo "Mail Was Sent";
} else {
echo "Mail Was No Sent";
}

?>

Ok, a few explanations:

You can alter the e-mail message and the email addresses, subject ect.

\r\n is basically a newline

the foreach loop part will seem a bit confusing if you are new to programming. Basically, what it does, is it takes all the form data ($_POST) data, and makes it into the form of:

input name : user inputted value


Lets say I am a user and I put in the name Matt and the email matt@nospam.net. When I submit the form, email.php will make an email that looks like:

--------------
A new registration on your site

name: Matt
email: matt@nospam.net

End of Email

---------------


This may seem very daunting, but have a go and if you have any problems post back here and we can help out. This was the first thing i really tried in php :)

kaattis
02-22-2004, 03:01 AM
wow....thanks matt, it's exactly what I was looking for. Thanks again, i'm going to go try it out now.....:D i'll be back with the result.

kaattis
02-22-2004, 05:43 AM
well, ok, here's the deal, the e-mail part is working, and I'm getting the message, but the only that shows in it is "End of Email". Here's what I have for the code:

<?php

$emailmessage = "A new registration on your site\r\n\r\n";


foreach($_POST as $key => $value){
$emailmessage .= $name . ": ". $value . "\r\n";
}

$emailmessage = "\r\nEnd of Email\r\n";

$to = "kat@site.org";
$subject = "New Registration";
$headers = reg@site.org;

if(mail($to, $subject, $emailmessage, $headers)){
echo "Form Was Sent";
} else {
echo "Form Was No Sent";
}

?>

i figured out a way to add all of the field names into the e-mail body, and it works nicely, but it's a lengthy code, I would really like to make this one work, for the future forms where I might have 50 or more fields.

Thanks :)

oracleguy
02-22-2004, 08:31 AM
Can you post the html for the form?

Nightfire
02-22-2004, 05:07 PM
$emailmessage .= "\r\nEnd of Email\r\n";

There was a missing . before the = :)

kaattis
02-22-2004, 05:49 PM
It worked, thank you :) i actually learnt something today!!!!!!!!!

missing-score
02-22-2004, 06:18 PM
cheers nightfire missed that one and im glad I could help out.


i figured out a way to add all of the field names into the e-mail body, and it works nicely, but it's a lengthy code, I would really like to make this one work, for the future forms where I might have 50 or more fields.


the foreach() loop part should do this, was it not working becuase of my missing . on the = sign, or are you still using the large ammount of code?

kaattis
02-22-2004, 07:28 PM
it wasn't working because of the missing dot

I'm using your code now, well, modified a little and corrected syntax :p thanks....

missing-score
02-22-2004, 07:43 PM
heheh. Im terrible when it comes to posting on CF, theres always obvious mistakes that i never see in my code. Glad you got it working :)