need help creating email box on site

birrdesigns

New Member
Messages
6
Reaction score
0
Points
0
I would like to create a page that allows viewers to type into a box and check radio buttons and then submit the information to me via email. I have very limited programming knowledge but would like to add this feature to my website. I have access to dreamweaver to edit my site. thanks to anyone who can give me any advice.
 

monpire

New Member
Messages
16
Reaction score
0
Points
0
I would like to create a page that allows viewers to type into a box and check radio buttons and then submit the information to me via email. I have very limited programming knowledge but would like to add this feature to my website. I have access to dreamweaver to edit my site. thanks to anyone who can give me any advice.

You can pretty much add mailto in the "method", but very insecure, read this:

http://www.netmechanic.com/news/vol3/form_no4.htm
 

ichwar

Community Advocate
Community Support
Messages
1,454
Reaction score
7
Points
0
No, mailto isn't good I think. It's better to go with a php form that uses the mail() function.

An example of this is something like this:

form.html
HTML:
<form name="submit" action="send.php" type="post">
<input type="text" name="message" />
<input type="submit" value="submit" />
</form>

send.php
PHP:
<?php
if ($_POST[message] == "")
{
header(form.html);
exit;
}

$email = "youremailaddresshere";
$msg = "$_POST[message]";
mail($email, $msg);

$name= "yournamehere";
echo "Your message" . $msg . "has been sent to" . $name;
?>

I'm going to need someone else here to confirm that code, since I typed it from memory so it is bound to have errors.
But it's something to start with if you want to use the php mail() function.
 

omniuni

New Member
Messages
21
Reaction score
0
Points
0
Hi birrdesigns,

Let's see what we can do. We'll write a piece of PHP code that...


  1. If the user has not clicked "Submit" display the form.
  2. If the user has submitted the form, send you a mail, and display a message.
  3. Uses only one page.
  4. Automatically finds values, so you don't need to modify the PHP, just the HTML for the form.
OK. Wherever you want the form to display, just insert this code:

PHP:
<?php
if($_POST['formsubmitted'] == true){
$mailto = 'youremail@example.com'; //your email address here
$subject = 'eMail From Website'; //change your subject line
$message = 'Message sent from website:'."\r\n"; //header for the eMail
//Notice the \r\n which adds a line break.

//now let's assemble the message:
foreach($_POST as $key => $value){
if(strpos($key,'formvalue')){
//this looks through the posted information to find anything submitted
//that has "formvalue" as part of the name. It returns true if it does.
$message.="$key: $value \r\n"; //appends the value along with the label to the message.
}
}

//now we try to send, and if it works display a message.

$successMessage = 'Thank you for your time.'; //Modify your message

if(mail($mailto, $subject, $message)){
//the mail function returns true if it is successful
echo $successMessage;
}else{
echo 'I\'m sorry, there was a problem submitting your data.';
}

}else{
//this is the form for information. note that all name attributes have
//"formvalue-" as part of them, which will later be used to assemble the message.
echo '
<form action="?" method="post">
What is your name? <input type="text" name="formvalue-name" size="30" />
What is your age? <input type="text" name="formvalue-age" size="30" />
<input type="submit" name="formsubmitted" value="true" />
</form>
';
}
?>

Good Luck! Let me know if that helps.
 
Last edited:
Top