Submission to SQL Database & Send Email?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1330

    #1

    Tech Submission to SQL Database & Send Email?

    How would I go about changing my submission.php coding so that when someone sends info across to the database, it also sends me an email to let me know?

    This is my submission.php file contents presently:

    <?php
    $link = mysqli_connect("localhost", "database", "password", "username");

    // Check connection
    if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
    }

    // Escape user inputs for security
    $title = mysqli_real_escape_string($link, $_REQUEST['title']);
    $recipe = mysqli_real_escape_string($link, $_REQUEST['recipe']);
    $description = mysqli_real_escape_string($link, $_REQUEST['description']);
    $category = mysqli_real_escape_string($link, $_REQUEST['category']);
    $name = mysqli_real_escape_string($link, $_REQUEST['name']);
    $email = mysqli_real_escape_string($link, $_REQUEST['email']);

    // Attempt insert query execution
    $sql = "INSERT INTO Directory (title, recipe, description, category, name, email) VALUES ('$title', '$recipe', '$description', '$category', '$name', '$email')";
    if(mysqli_query($link, $sql)){
    echo "Records added successfully.";
    } else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
    }

    // Close connection
    mysqli_close($link);
    ?>4
    Am I able to just fuck with the code from my feedback form code and append it onto the end of the code in submission.php above?

    <?php
    if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[email protected]";
    $email_subject = "New Recipe Submission";

    }
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    Any pointers in the right direction would be appreciated
    Extreme Link List - v1.0
  • ZTT
    Confirmed User
    • Apr 2019
    • 659

    #2
    Whatever you do, don't spend five seconds trying it before asking here. That would be crazy.
    __________________

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1330

      #3
      Originally posted by ZTT
      Whatever you do, don't spend five seconds trying it before asking here. That would be crazy.
      I have tried and its not working, I'm asking if there is another option to just appending and showing what I already tried.
      Extreme Link List - v1.0

      Comment

      • ZTT
        Confirmed User
        • Apr 2019
        • 659

        #4
        Have you have tested your email form so you know it definitely works? Some servers may block it, and some email providers may not accept such email. If it works - that is you submit a form and receive an email - there should be no issue with using the mail function when people submit data.

        BTW you don't need all that header shit on an email. You need To, Subject, Message, From. For example this is probably enough to test with (obviously with real email addresses), after or before your "records added successfully" line:

        mail("me@myhouse","Hello","How are you","From: you@yourhouse");

        Edit: since newlines may be necessary, even with one line of headers (from): mail("me@myhouse","Hello","How are you","From: you@yourhouse\r\n");
        __________________

        Comment

        • sarettah
          see you later, I'm gone
          • Oct 2002
          • 14296

          #5
          I would do it inside the if checking results from the query.

          if(mysqli_query($link, $sql)){
          echo "Records added successfully.";

          // ...............Do the email shit right here................

          $emailsubj="subject of my email";

          $emailsendaddress="[email protected]";

          $emailaddy2use="address I am sending to";

          $headers = "MIME-Version: 1.0\r\n";
          $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
          $headers .="From: " . $emailsendaddress . "\r\n";

          mail ( $emailaddy2use, $emailsubj, $emailmessage, $headers);

          }
          All cookies cleared!

          Comment

          • sarettah
            see you later, I'm gone
            • Oct 2002
            • 14296

            #6
            Never mind...

            .
            All cookies cleared!

            Comment

            • ZTT
              Confirmed User
              • Apr 2019
              • 659

              #7
              Whatever you do, don't spend five seconds reading a four post thread before repeating what's in it. That would be crazy.
              __________________

              Comment

              • sarettah
                see you later, I'm gone
                • Oct 2002
                • 14296

                #8
                Originally posted by ZTT
                Whatever you do, don't spend five seconds reading a four post thread before repeating what's in it. That would be crazy.
                What?

                .
                All cookies cleared!

                Comment

                • ZTT
                  Confirmed User
                  • Apr 2019
                  • 659

                  #9
                  I said:

                  Whatever you do, don't spend five seconds reading a four post thread before repeating what's in it. That would be crazy.

                  Do you get paid per sig view?
                  __________________

                  Comment

                  • sarettah
                    see you later, I'm gone
                    • Oct 2002
                    • 14296

                    #10
                    Originally posted by ZTT
                    I said:

                    Whatever you do, don't spend five seconds reading a four post thread before repeating what's in it. That would be crazy.

                    Do you get paid per sig view?
                    What the fuck are you talking about?

                    Where, in the posts before mine, do you tell him that you would move the email send into the if statement testing the query, or anything like that.

                    Dude asked:
                    How would I go about changing my submission.php coding so that when someone sends info across to the database, it also sends me an email to let me know?

                    And later said:
                    I'm asking if there is another option to just appending and showing what I already tried.

                    I gave him another option, moving it into the if statement after the query rather than doing another if.

                    So, where the fuck did I repeat everything that is already in the thread? The email shit, I just pasted that in there to demonstrate where I would drop it in.

                    Now, you have a problem with me? I suggest you ignore me.

                    Oh, yeah. Go Fuck Yourself, asshole.

                    ,
                    All cookies cleared!

                    Comment

                    • sarettah
                      see you later, I'm gone
                      • Oct 2002
                      • 14296

                      #11
                      Originally posted by ZTT

                      after or before your "records added successfully" line:
                      Ok, I just saw that when I looked really hard, I had gone past it earlier because it was combined in with another idea.

                      Sorry about that.

                      Still, fuck you for being an asshole about it.

                      .
                      All cookies cleared!

                      Comment

                      • Publisher Bucks
                        Confirmed User
                        • Oct 2018
                        • 1330

                        #12
                        Originally posted by sarettah
                        I would do it inside the if checking results from the query.
                        Can I ask why there? Is there a specific reason or is that just the 'correct' way of doing it?
                        Extreme Link List - v1.0

                        Comment

                        • Publisher Bucks
                          Confirmed User
                          • Oct 2018
                          • 1330

                          #13
                          Originally posted by ZTT
                          Have you have tested your email form so you know it definitely works? Some servers may block it, and some email providers may not accept such email. If it works - that is you submit a form and receive an email - there should be no issue with using the mail function when people submit data.

                          BTW you don't need all that header shit on an email. You need To, Subject, Message, From. For example this is probably enough to test with (obviously with real email addresses), after or before your "records added successfully" line:

                          mail("me@myhouse","Hello","How are you","From: you@yourhouse");

                          Edit: since newlines may be necessary, even with one line of headers (from): mail("me@myhouse","Hello","How are you","From: you@yourhouse\r\n");
                          Yes, the form works on several other sites that I have it on, which was why I'm choosing to use this specific form

                          Thank you.
                          Extreme Link List - v1.0

                          Comment

                          • Publisher Bucks
                            Confirmed User
                            • Oct 2018
                            • 1330

                            #14
                            Moving it to that position worked great and I even managed to add a html template page to the bottom of the code so it matches the rest of the site layout.

                            Thank you both for the assistance

                            Next on my list if the CRUD system which is almost done I just need to add a few stylesheets
                            Extreme Link List - v1.0

                            Comment

                            • ZTT
                              Confirmed User
                              • Apr 2019
                              • 659

                              #15
                              Originally posted by sarettah
                              Ok, I just saw that when I looked really hard, I had gone past it earlier because it was combined in with another idea.

                              Sorry about that.

                              Still, fuck you for being an asshole about it.

                              .
                              I'm an asshole for making a jokey callback to something I posted to the OP (who unlike you didn't have a total meltdown about it) because reading a four post thread before posting to it is "really hard" for you?
                              __________________

                              Comment

                              Working...