Formmailer

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Ich brauche eure Hilfe!

    Nun bin ich soweit.
    Ich habe alle Komponenten zusammen.
    Eine Validierung die Highlightet...

    Quellcode

    1. <?
    2. function error_bool($error, $field) {
    3. if($error[$field]) {
    4. print("<td style=color:red>");
    5. }
    6. else {
    7. print("<td>");
    8. }
    9. }
    10. function show_form() {
    11. global $HTTP_POST_VARS, $print_again, $error;
    12. ?>
    13. <form action="" method="post">
    14. <table width="400" border="1" cellspacing="0" cellpadding="0">
    15. <tr>
    16. <?php error_bool($error, "name"); ?> Name </td>
    17. <td><input name="name" type="text" id="name" value="<? echo $_POST["name"]; ?>"></td>
    18. </tr>
    19. <tr>
    20. <?php error_bool($error, "email"); ?> Email </td>
    21. <td><input name="email" type="text" id="email" value="<? echo $_POST["email"]; ?>"></td>
    22. </tr>
    23. <tr>
    24. <td><input type="submit" name="Submit" value="Submit"></td>
    25. <td> </td>
    26. </tr>
    27. </table>
    28. </form>
    29. <?
    30. }
    31. if(isset($_POST["Submit"])) {
    32. check_form();
    33. } else {
    34. show_form();
    35. }
    36. function check_email_address($email) {
    37. // First, we check that there's one @ symbol, and that the lengths are right
    38. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    39. // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    40. return false;
    41. }
    42. // Split it into sections to make life easier
    43. $email_array = explode("@", $email);
    44. $local_array = explode(".", $email_array[0]);
    45. for ($i = 0; $i < sizeof($local_array); $i++) {
    46. if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
    47. return false;
    48. }
    49. }
    50. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    51. $domain_array = explode(".", $email_array[1]);
    52. if (sizeof($domain_array) < 2) {
    53. return false; // Not enough parts to domain
    54. }
    55. for ($i = 0; $i < sizeof($domain_array); $i++) {
    56. if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
    57. return false;
    58. }
    59. }
    60. }
    61. return true;
    62. }
    63. function check_form()
    64. {
    65. global $HTTP_POST_VARS, $error, $print_again;
    66. $error['name'] = false;
    67. if($_POST["name"]=="") {
    68. $error['name'] = true;
    69. $print_again = true;
    70. $message="The name field is empty<br>";
    71. }
    72. if(!check_email_address($_POST['email'])) {
    73. $error['email'] = true;
    74. $print_again = true;
    75. $message.="Either Field Empty or Invalid Email ID <br>";
    76. }
    77. if($print_again) {
    78. show_form();
    79. } else {
    80. show_form();
    81. $message="All Fields are valid <br>
    82. Now, In this way you can validate the other textfield as well<br>
    83. You can insert data into table";
    84. }
    85. echo "$message";
    86. }
    87. ?>
    Alles anzeigen


    Doch nun, wie baue ich die mail() Angaben darin?

    Quellcode

    1. <?php
    2. $Empfaenger = "eine@mailadresse.de";
    3. $Betreff = "Feedback";
    4. $Nachricht = "
    5. // Das Formular
    6. ";
    7. $Header = "MIME-Version: 1.0\n";
    8. $Header .= "Content-type: text/html; charset=iso-8859-1\n";
    9. mail($Empfaenger, $Betreff, $Nachricht, $Header);
    10. ?>
    Alles anzeigen


    Wäre froh wenn mir das jemand erklären könnte :shock:
  • Re: Also ok, das war nix...

    "Michel" schrieb:

    Wie meinst du das, $Empfaenger wird dann noch $_POST['email'] zugewiesen?


    Also wie gesagt. 87 bis 90 würd ich einfach durch die folgenden Zeilen ersetzen.
    $_POST['email'] hab ich im Folgenden schon ersetzt.

    Deine Nachricht musst du natürlich noch selbst zusammenstricken...
    Aber dazu sind ja auch noch keine Felder im Formular vorhanden.

    Quellcode

    1. <?php
    2. $Empfaenger = "eine@mailadresse.de";
    3. $Betreff = "Feedback";
    4. $Nachricht = "
    5. // Das Formular
    6. ";
    7. $Header = "MIME-Version: 1.0\n";
    8. $Header .= "Content-type: text/html; charset=iso-8859-1\n";
    9. mail($Empfaenger, $Betreff, $Nachricht, $Header);
    10. ?>
    Alles anzeigen
  • unexpected T_CONSTANT_ENCAPSED_STRING

    unexpected T_CONSTANT_ENCAPSED_STRING
    line 71

    Quellcode

    1. <?
    2. function error_bool($error, $field) {
    3. if($error[$field]) {
    4. print("<td style=color:red>");
    5. }
    6. else {
    7. print("<td>");
    8. }
    9. }
    10. function show_form() {
    11. global $HTTP_POST_VARS, $print_again, $error;
    12. ?>
    13. <form action="" method="post">
    14. <table width="400" border="1" cellspacing="0" cellpadding="0">
    15. <tr>
    16. <?php error_bool($error, "name"); ?> Name </td>
    17. <td><input name="name" type="text" id="name" value="<? echo $_POST["name"]; ?>"></td>
    18. </tr>
    19. <tr>
    20. <?php error_bool($error, "email"); ?> Email </td>
    21. <td><input name="email" type="text" id="email" value="<? echo $_POST["email"]; ?>"></td>
    22. </tr>
    23. <tr>
    24. <td><input type="submit" name="Submit" value="Submit"></td>
    25. <td> </td>
    26. </tr>
    27. </table>
    28. </form>
    29. <?
    30. }
    31. if(isset($_POST["Submit"])) {
    32. check_form();
    33. } else {
    34. show_form();
    35. }
    36. function check_email_address($email) {
    37. // First, we check that there's one @ symbol, and that the lengths are right
    38. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
    39. // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    40. return false;
    41. }
    42. // Split it into sections to make life easier
    43. $email_array = explode("@", $email);
    44. $local_array = explode(".", $email_array[0]);
    45. for ($i = 0; $i < sizeof($local_array); $i++) {
    46. if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
    47. return false;
    48. }
    49. }
    50. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
    51. $domain_array = explode(".", $email_array[1]);
    52. if (sizeof($domain_array) < 2) {
    53. return false; // Not enough parts to domain
    54. }
    55. for ($i = 0; $i < sizeof($domain_array); $i++) {
    56. if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
    57. return false;
    58. }
    59. }
    60. }
    61. return true;
    62. }
    63. function check_form()
    64. {
    65. global $HTTP_POST_VARS, $error, $print_again;
    66. $error['name'] = false;
    67. if($_POST["name"]=="") {
    68. $error['name'] = true;
    69. $print_again = true;
    70. $message="The name field is empty<br />";
    71. }
    72. if(!check_email_address($_POST['email'])) {
    73. $error['email'] = true;
    74. $print_again = true;
    75. $message.="Either Field Empty or Invalid Email ID <br />";
    76. }
    77. if($print_again) {
    78. show_form();
    79. } else
    80. {
    81. $Empfaenger = "info@example.com";
    82. $Betreff = "Feedback";
    83. $Nachricht = "<form action="" method="post">
    84. <table width="400" border="1" cellspacing="0" cellpadding="0">
    85. <tr>
    86. <td>Name
    87. <td>
    88. <input name="name" type="text" id="name">
    89. </td>
    90. </tr>
    91. <tr>
    92. <td>Email
    93. <td>
    94. <input name="email" type="text" id="email">
    95. </td>
    96. </tr>
    97. <tr>
    98. <td><input type="submit" name="Submit" value="Submit"></td>
    99. <td> </td>
    100. </tr>
    101. </table>
    102. </form>";
    103. $Header = "MIME-Version: 1.0\n";
    104. $Header .= "Content-type: text/html; charset=iso-8859-1\n";
    105. mail($Empfaenger, $Betreff, $Nachricht, $Header);
    106. }
    107. echo "$message";
    108. }
    109. ?>
    Alles anzeigen