 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
deafdigit
Joined: 03 May 2008 Posts: 1
|
Posted: Sat May 03, 2008 8:39 am Input type and email |
|
|
|
I've been looking through the forum, and I don't think I see a question answered, that delivers quite the help I need. On the other hand, I think answering this question would helt a lot of people!
I'm writing an applicationform for a MMORPG guild's website, and I need a little help with the following...
The applicationform contains both textboxes, dropdown menues (select - /select), radiobutons and checkboxes. I need to find a way to get the info from said boxes, cram it all up into an email message, and send it to my e-mail. I realise this is a bit of work, and requires both HTML and PHP (and JavaScript?), but I'm really stuck, and I would love some help.
If someone could please write me an example code with one textbox, two radiobuttons, two checkboxes and one dropdownmenu (with multiple choices) - and the code that sends me the email I would be forever in your debt.
Help is much appreciated - regardless of my spelling it wrong
//deafdigit |
|
rsleventhal

Joined: 19 Mar 2008 Posts: 20
|
Posted: Wed May 07, 2008 11:16 am |
|
|
|
Hi deafdigit,
What you're asking isn't difficult at all.
1st, ensure that each of your form elements have the 'name' attribute set. ex:
| Code: |
<label for="Fname">First Name<br />
<input type="text" name="Fname" /> |
Also, make certain that your form is using the 'post' method and that you point it to a php script (which is included here) called process.php. Your <form> tag should look something like this:
| Code: |
| <form action="process.php" method="post"> |
When using 'post', PHP will take each of the html form elements and push them into an array called $_POST.
So, the script below takes each of these elements and parses them before creating the email. Note: if you use the 'name' attribute carefully and semantically, it will serve you well. Fname, as an example, for 'First Name' and so on...
The email generated by the script will come in plain text in the format:
element name: value
So if I'd filled out Fname to be 'Ray', you'd get:
Fname: Ray
... and so on.
here's the basic script.
| Code: |
<?php
if ( $_SERVER['REQUEST_METHOD'] == "POST" )
{
// In testing, if you get an Bad referer error
// comment out or remove the next three lines
if (strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])>7 ||
!strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']))
die("Bad referer");
$msg = "Values submitted by the user:\n";
foreach( $_POST as $key => $val )
{
if ( is_array( $val ) )
{
$msg .= "Item: $key\n";
foreach( $val as $v )
{
$v = stripslashes( $v );
$msg .= " $v\n";
}
}
else
{
$val = stripslashes( $val );
$msg .= "$key: $val\n";
}
}
// add IP address from server header, to bottom of email
$msg .= "The IP Address of the sender is: " . $REMOTE_ADDR;
$recipient = 'your email address goes here';
$subject = 'subject of the email goes here';
$from = $_POST['email'];
$headers = 'From: ' . $from . '<' . $from . '>';
error_reporting( 0 );
// if mail sends successfully, present a nice 'thank you' on screen
if ( mail( $recipient, $subject, $msg, $headers ) )
{
echo "<center>";
echo "<br>";
echo "<h1>Thank you</h1><p>Thank you for completing our form!</p>\n";
echo "<p>Any additional thank you message can go here.";
echo "</center>";
echo nl2br( $input );
}
else
echo "An error occurred and the message could not be sent.";
}
else
echo "Bad request method";
?>
|
Save the code above as 'process.php' and point to it as your 'action' as described earlier.
I hope this helps.
If you have any questions, feel free to post here so that more may benefit from the answers.
Regards,
-Ray |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|