Send form by email

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

I'm sure that this has been posted somewhere on here, but this is what I'm wanting to do. If I have a simple contact form and when the person filling it out, hits submit, not only will it post to the database, which I have no problem doing, but I also want that to send a copy of the form to a email, which is where I don't know how to do. Can somebody help?

Thanks,
Jordon
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

What programming language are you using to submit the data to the database?
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Sorry, I should have said. I used PHP.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

After your code to post to the database just add code for the php mail

Here's a link to syntax, and scroll down for four examples

http://cl.php.net/manual/en/function.mail.php
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

awesome, thanks!
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Ok, I've just now got around to trying this; however, it isn't working. I can't get it to mail. Here is my action script, can you review and see where I'm going wrong?

Code: [ Select ]
<?php
    if (isset($_POST['submit'])){
    $errors = array();
    
     $required_fields = array('f_name', 'l_name', 'u_name', 'p_word');
     $errors = array_merge($errors, check_required_fields($required_fields, $_POST));
     $firstname = stripslashes(str_replace("'", "''", ($_POST['f_name'])));
     $lastname = stripslashes(str_replace("'", "''", ($_POST['l_name'])));
     $username = stripslashes(str_replace("'", "''", ($_POST['u_name'])));
     $password = stripslashes(str_replace("'", "''", ($_POST['p_word'])));
     $hashed_password = sha1($password);
     $access = $_POST['alevel'];
    
     if ( empty($errors)) {
        $query = "INSERT INTO SNP_Users (
                    first_name, last_name, username, password, access_level)
                    VALUES (
                     '{$firstname}', '{$lastname}', '{$username}', '{$hashed_password}', '{$access}'
                     )";
        $result = mssql_query($query, $connection);
        if ($result) {
            mail('wjshaw@shawhome.net', 'New User Created', '$firstname $lastname was created');
            $message = "The user was successfully created.";
        } else {
         $message = "The user could not be create.";
         $message .= "<br />" . mssql_error();
        }
     } else {
        if (count($errors) == 1) {
         $message = "There was 1 error in the form.<br />Please check required fields!" ;
        } else {
         $message = "There were " . count($errors) . " errors in the form.<br />Please check required fields!";
        }
     }
} else { //Form has not been submitted.
     $firstname = "";
     $lastname = "";
     $username = "";
     $password = "";
}

?>
  1. <?php
  2.     if (isset($_POST['submit'])){
  3.     $errors = array();
  4.     
  5.      $required_fields = array('f_name', 'l_name', 'u_name', 'p_word');
  6.      $errors = array_merge($errors, check_required_fields($required_fields, $_POST));
  7.      $firstname = stripslashes(str_replace("'", "''", ($_POST['f_name'])));
  8.      $lastname = stripslashes(str_replace("'", "''", ($_POST['l_name'])));
  9.      $username = stripslashes(str_replace("'", "''", ($_POST['u_name'])));
  10.      $password = stripslashes(str_replace("'", "''", ($_POST['p_word'])));
  11.      $hashed_password = sha1($password);
  12.      $access = $_POST['alevel'];
  13.     
  14.      if ( empty($errors)) {
  15.         $query = "INSERT INTO SNP_Users (
  16.                     first_name, last_name, username, password, access_level)
  17.                     VALUES (
  18.                      '{$firstname}', '{$lastname}', '{$username}', '{$hashed_password}', '{$access}'
  19.                      )";
  20.         $result = mssql_query($query, $connection);
  21.         if ($result) {
  22.             mail('wjshaw@shawhome.net', 'New User Created', '$firstname $lastname was created');
  23.             $message = "The user was successfully created.";
  24.         } else {
  25.          $message = "The user could not be create.";
  26.          $message .= "<br />" . mssql_error();
  27.         }
  28.      } else {
  29.         if (count($errors) == 1) {
  30.          $message = "There was 1 error in the form.<br />Please check required fields!" ;
  31.         } else {
  32.          $message = "There were " . count($errors) . " errors in the form.<br />Please check required fields!";
  33.         }
  34.      }
  35. } else { //Form has not been submitted.
  36.      $firstname = "";
  37.      $lastname = "";
  38.      $username = "";
  39.      $password = "";
  40. }
  41. ?>
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Are you getting any error messages? Because you should... you aren't putting the 'from' field in there (As an additional header).
PHP Code: [ Select ]
mail($to, $subject, $message, "FROM <!-- e -->admin@site.com<!-- e -->");

Also, are you testing locally or on your server?

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 96 guests
  • 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 post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.