Forum Moderators: open

Message Too Old, No Replies

Creating a Form

and getting the results emailed to me

         

tml89

7:36 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



I just discovered that the simple mailto function for creating a from does not work. (yes thats bad I just discovered it)

What is the best way to make a simple form?
ie, name, howd you find us, comments.

And have the info emailed to myself?

I tried doing this in frontpage and its a pain in the ass, Id rather just hand code this part.

WhosAWhata

7:39 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



you need to pass it through some type of server-side script (PHP, PERL, etc) what do you have support for?

tml89

7:47 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



I am hosted at godaddy

WhosAWhata

8:00 pm on Jun 23, 2004 (gmt 0)

10+ Year Member



if you did economy you have PHP if you have an upgraded account you also have either PERL (linux) or ASP (windows)

any of these can send mail
since i know you have PHP,
take a look at
PHP's Mail Functions [php.net]

AND/OR

a tutorial
A Feedback form [thesitewizard.com]

AND/OR

look at mail scripts like this

FormMail [dtheatre.com]

tml89

8:01 pm on Jun 25, 2004 (gmt 0)

10+ Year Member



Whew that looks a little confusing :-)

I need to use that to have a form? I just need simple stuff like name, how did you find us, email addresse, comments.

I have not really worked with PHP before, but I guess theres a first time for everything.

BTW, I am on the economy plan

edpudol

9:12 am on Jun 26, 2004 (gmt 0)

10+ Year Member



Well if you don't really like to use those scripts, it's really hard to do what you want.

I think this still working but need the visitor to use his/her email program to send the form result. here is the code.

<form method = post action = "mailto:youremailad@ip.com">

if won't work remove the?subject:'Just simple form'

this will work, but need to use the client email

tml89

4:25 pm on Jun 26, 2004 (gmt 0)

10+ Year Member



What about creating the form with the form feature in frontpage?

tedster

9:16 pm on Jun 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That would be one relatively easy way to do it and not have to dip into any server-side code yourself - just know that your server must have FrontPage extensions installed to make it work.

If you need some help with FrontPage forms, we have a WYSIWYG Editors Forum [webmasterworld.com] where the best Front Page discussions are held.

[edited by: tedster at 9:19 pm (utc) on June 27, 2004]

soapystar

7:34 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



its a shame that fp extensions ruin your htaccess files.

tml89

8:11 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



I tried putting together a form with frontpage, that emails me the results. It says that frontpage extensions need to be installed in order for it to work. When I go to my pannel in godaddy, it says they are installed. (they have to be to use the publish web option) But I cant seem to get the thing to work.

tedster

9:31 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Doesn't work in what way?

If the form looks alright online, and it seems to take your input but you never get the email -- then make sure there are no typos in your e-mail address in the Front Page "Form Properties" dialog box.

If you published the page to the server, but when you look at with your browser you see a line that says [FrontPage Save Results Component], then it's time to call support at your Web hosting company.

tml89

10:07 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



I see the form, but I also see the [FrontPage Save Results Component], I have emailed them regaridng the issue and am awaiting a reply.

mack

10:28 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Here is come code that should work for you.

<?php
$receiverMail= "you@example.com";
$name= ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email= ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$subject= ltrim(rtrim(strip_tags(stripslashes($_POST['subject']))));
$msg= ltrim(rtrim(strip_tags($_POST['msg'])));
$ip= getenv("REMOTE_ADDR");
$msgformat= "From: $name ($ip)\nEmail: $email\n\n$msg";
if(empty($name) ¦¦ empty($email) ¦¦ empty($subject) ¦¦ empty($msg)) {
echo "<h3>the email failed</h3><p>Please fill all the fields</p>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "<h3>The email was not sent</h3><p>The email address is incorect</p>";
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>Your email has been sent!</h3><p>someone from us will get back to you as soon as possible.</p>"; }
?>

save this as something like mail.php

you will then need to create a form to call mail.php ...

<form method="post" action="path/to/mail.php">
Name:<br /><input name="name" type="text" size="40" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="40" maxlength="40" /><br /><br />
Subject:<br /><input name="subject" type="text" size="40" maxlength="40" /><br /><br />
Message:<br /><textarea name="msg" cols="60" rows="10"></textarea><br /><br />
<input type="reset" value="Reset" />&nbsp;<input type="submit" value="Send" />
</form>

You need to set your email address in mail.php to point to the correct location. You also need to alter the form to point to the php script.

Hope this is of some help.

Mack.

tml89

10:36 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Is there any good threads/resources I can read so I can understand that last post ;-)

BlobFisk

10:46 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi tml89,

If you do some reading on form to mail scripts macks post will be crystal clear!

Basically it takes the data from the form and sends it to an email address. Macks example is in php, but this can be done in any server side language.

HTH

tml89

10:47 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



So I still create the form with frontpage, and then the script sends the to the email addresse?

mack

10:59 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If youre using frontpage you can place the html code on the page using insert>advanced>html

That should work.

Mack.

tml89

11:11 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



Under form properties, do I select send to: other: customs script?

mack

11:33 pm on Jun 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I tend not to use form properties at all. Just use the form code as a stand alone section of html. When the cursor is in the place you want to place your form simply go to insert>advanced>html. Paste your code into the box that appears and click ok. Now save your page and preview. The form should work now.

Mack.

tml89

11:39 pm on Jun 27, 2004 (gmt 0)

10+ Year Member



So paste the form code from above into the page where I want it?

When I tried to save that script as mail.php it was a picture it document?

mack

12:35 am on Jun 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Yep on windows if you click on a php file it tries to open it in microsoft picture it publishing. To view the file use right click then open with. Select either notepad or word pad.

Also note... the script will not work until you upload it to your host. This is because it requires a server environment to run (php installed). The script would only work on your machine if you have a server installed (apache/iis) and php.

I think also you may have picked up some of my post wrong. The first piece of code is the script. Save it as mail.php the second section of code is the html you paste into your web page.

Mack.

WhosAWhata

1:47 am on Jun 29, 2004 (gmt 0)

10+ Year Member



here i'll give you an edited version of mack's code that will let you stop messing with frontpage and everything, all you need to do is create a file with a .php extension and you will have to change your email address in the code

this code adds the form to the same page so you won't have to make seperate pages


[pre]<?php
$receiverMail= "[b]you@example.com[/b]";

if($_POST['name'] && $_POST['email'] && $_POST['subject'] && $_POST['msg']){
$name= ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email= ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$subject= ltrim(rtrim(strip_tags(stripslashes($_POST['subject']))));
$msg= ltrim(rtrim(strip_tags($_POST['msg'])));
$ip= getenv("REMOTE_ADDR");
$msgformat= "From: $name ($ip)\nEmail: $email\n\n$msg";
if(empty($name) ¦¦ empty($email) ¦¦ empty($subject) ¦¦ empty($msg)) {
echo "<h3>the email failed</h3><p>Please fill all the fields</p>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "<h3>The email was not sent</h3><p>The email address is incorect</p>";
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>Your email has been sent!</h3><p>someone from us will get back to you as soon as possible.</p>"; }
} else {
echo '<form method="post" action="'.$PHP_SELF.'">
Name:<br /><input name="name" type="text" size="40" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="40" maxlength="40" /><br /><br />
Subject:<br /><input name="subject" type="text" size="40" maxlength="40" /><br /><br />
Message:<br /><textarea name="msg" cols="60" rows="10"></textarea><br /><br />
<input type="reset" value="Reset" />&nbsp;<input type="submit" value="Send" />
</form>';
}
?>[/pre]