trivector Posted July 3, 2006 Share Posted July 3, 2006 I'm writing this mail form and I don't know how to get user input from the fields Name and Email. I have tried using $_GET, $_REQUEST, and $_POST, but everytime I run it, I get this error:Notice: Undefined index: Email in c:\appserv\www\default.php on line 74Can anyone please help? Here's my code:Name: <input type="text" name="Name" /><br><br> Email: <input type="text" name="Email" /><br><br> Message:<br><br> <textarea rows="8" cols="50" name="Message" ></textarea> <br><br> Thank you for visiting the site. <br><br> <input type="submit" value="Send"/> <br><? php$name = $_GET["Name"];$from = $_GET["Email"];?>Thanks in advance. Link to comment Share on other sites More sharing options...
Jeyalakshmi Posted July 3, 2006 Share Posted July 3, 2006 I'm writing this mail form and I don't know how to get user input from the fields Name and Email. I have tried using $_GET, $_REQUEST, and $_POST, but everytime I run it, I get this error:Notice: Undefined index: Email in c:\appserv\www\default.php on line 74Can anyone please help? Here's my code:Name: <input type="text" name="Name" /><br><br> Email: <input type="text" name="Email" /><br><br> Message:<br><br> <textarea rows="8" cols="50" name="Message" ></textarea> <br><br> Thank you for visiting the site. <br><br> <input type="submit" value="Send"/> <br><? php$name = $_GET["Name"];$from = $_GET["Email"];?>Thanks in advance.<{POST_SNAPBACK}> do you want to validate that e mail form or simply you are creating email form. in html you didnt specify any form tag.check this link www.php.net this is the complete resource for phpwhat you going to do explain clearlythanks Link to comment Share on other sites More sharing options...
pulpfiction Posted July 3, 2006 Share Posted July 3, 2006 Try this. <html><body><? php$mode = $_GET["mode"];if ($mode=="getdata"){$name = $_GET["Name"];$from = $_GET["Email"];echo "User Name: $name \n Email: $from"}?><form action="samepage.php" method=get>Name: <input type="text" name="Name" /><br><br>Email: <input type="text" name="Email" /><br><br>Message:<br><br><textarea rows="8" cols="50" name="Message" ></textarea><br><br>Thank you for visiting the site.<br><br><input type="submit" value="Send" /><br><input type="hidden" name="mode" value="getdata" /></form></body></html> Link to comment Share on other sites More sharing options...
trivector Posted July 3, 2006 Author Share Posted July 3, 2006 I want to create a mail form on my page, so that people can use it to send emails to me. Link to comment Share on other sites More sharing options...
pulpfiction Posted July 3, 2006 Share Posted July 3, 2006 This is the code to send mail...<?php$name = $_GET["Name"];$from = $_GET["Email"];$msg = $_GET["Message"];$to = "youraddr@example.com";$subject = "Mail from Name: $name, Email: $from";$body = $msg;if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); }?> Link to comment Share on other sites More sharing options...
scherpenzeel Posted July 4, 2006 Share Posted July 4, 2006 Hi this is a form i use and I have to say it goes like thunder. Its secure and spam protected. Very easy to use, just include the form in your page and it wil work.you only have to change the receivers e-mail adres. and the text (the parts are in red now are in dutch have fun with it. <? // the e-mail addres of receiver $mail_ontv = "info@yoursite.com";// is not 100% !!! function checkmail($mail) { $email_host = explode("@", $mail); $email_host = $email_host['1']; $email_resolved = gethostbyname($email_host); if ($email_resolved != $email_host && eregi("^[0-9a-z]([-_.~]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$mail)) $valid = 1; return $valid; } // if not submited, or submitted and forgot somethingsif (!$_POST['submit'] || $_POST['submit'] && (!$_POST['naam'] || !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['msggs'] || !$_POST['onderwerp'])) { if ($_POST['submit'] && (!$_POST['naam'] || !$_POST['mail'] || !checkmail($_POST['mail']) || !$_POST['msggs'] || !$_POST['onderwerp'])) { echo "forgot name, e-mail addres, or subject, text. "; echo "or the e-mail adres is not right.<p>"; } // form + tabel echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<form method=\"POST\" ACTION=\"" . $_SERVER['PHP_SELF'] . "\">"; // name echo "<tr><td>Name:</td></tr>"; echo "<tr><td><input type=\"text\" name=\"naam\" value=\"" . $_POST['naam'] . "\"></td></tr>"; // space echo "<tr><td> </td></tr>"; // mail echo "<tr><td>E-mail adres:</td></tr>"; echo "<tr><td><input type=\"text\" name=\"mail\" value=\"" . $_POST['mail'] . "\"></td></tr>"; // space echo "<tr><td> </td></tr>"; // mail echo "<tr><td>Onderwerp:</td></tr>"; echo "<tr><td><input type=\"text\" name=\"onderwerp\" value=\"" . $_POST['onderwerp'] . "\"></td></tr>"; // space echo "<tr><td> </td></tr>"; // mail echo "<tr><td>Bericht:</td></tr>"; echo "<tr><td><TEXTAREA name=\"msggs\" ROWS=\"6\" COLS=\"40\">" . htmlentities($_POST['msggs']) . "</TEXTAREA></td></tr>"; // space echo "<tr><td> </td></tr>"; // button echo "<tr><td> </td></tr>"; echo "<tr><td><input type=\"submit\" name=\"submit\" value=\"Versturen\"></td></tr>"; // close form + tabel echo "</form>"; echo "</table>"; } // sent to/ versturen naar else { // set date $datum = date("d.m.Y H:i"); // set ip $ip = $_SERVER['REMOTE_ADDR']; $inhoud_mail = "===================================================\n"; $inhoud_mail .= "mail from your site.....here name\n"; $inhoud_mail .= "===================================================\n\n"; $inhoud_mail .= "Naam: " . $_POST['naam'] . "\n"; $inhoud_mail .= "E-mail adres: " . $_POST['mail'] . "\n"; $inhoud_mail .= "Bericht:\n"; $inhoud_mail .= $_POST['msggs'] . "\n\n"; $inhoud_mail .= "Verstuurd op $datum via het ip " . $ip . "\n\n"; $inhoud_mail .= "===================================================\n\n"; // -------------------- // spambot protection // ------ // from tutorial: http://www.phphulp.nl/php/tutorials/10/340/ // ------ $headers = "From: " . $_POST['naam'] . " <" . $_POST['mail'] . ">"; $headers = stripslashes($headers); $headers = str_replace("\n", "", $headers); // Verwijder \n $headers = str_replace("\r", "", $headers); // Verwijder \r $headers = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $headers)); // Slashes van quotes $_POST['onderwerp'] = str_replace("\n", "", $_POST['onderwerp']); // Verwijder \n $_POST['onderwerp'] = str_replace("\r", "", $_POST['onderwerp']); // Verwijder \r $_POST['onderwerp'] = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $_POST['onderwerp'])); // Slashes van quotes mail($mail_ontv, $_POST['onderwerp'], $inhoud_mail, $headers); echo "your message has been send."; echo "Thaks for you reaction."; // echo "even more tekst here.</p>"; //echo "<p>and a other line here "; //echo "or what about this line here.</p>"; } ?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now