简体   繁体   中英

How to send email trigger notification to specific email within row when field is updated/inputted with data

Sorry for sounding like a broken record, i posted a similar question last week and have had some decent progress, but i need to go a step further.

So i have been pulling my hairs over this and need some guidance and help. In a nutshell, i need to be able to fill in an empty field(field is called "shippingnumber") within the database or custom back end, which would then trigger a custom email notification to the persons email within the same row. Here is what i got so far. We will be using the email "thisisatestemail2016@gmail.com" as an example. This is the email that the person will submit into the form below, and is also the same email which will receive the email notification when the field, "shippingnumber" has data put into it.

So i have created an order form ( http://www.topchoicedata.com/175.php#175 ). Here we have 5 fields the customer would enter with the option for an extra shipping cost. When the user submits, it will take them to a paypal payment page. At this point the persons info from the 5 fields has been inputted into a new row within the table database. When the person progresses further with the payment, the rest of the fields get inputted, all except for one, that field is called "shippingnumber". This is located in an hidden input field for the form mentioned above. Below is the html code for the $175 form, with the form action being done in a subfolder named PPPaymentForm/PPPaymentForm.php. Take notice of the "shippingorder" input below in the form.

<form action="PPPaymentForm/PPPaymentForm.php"  method="post" name="topchoiceform" id="topchoiceform">
    <input placeholder="Company Name" type="text" name="companyname" required>
    <input placeholder="First Name" type="text" name="firstname" required>
    <input placeholder="Last Name" type="text" name="lastname" required>
    <input placeholder="Email" type="email" name="email" id="email" required>
    <input placeholder="Address" type="text" name="address" required>
    <input name="shipping" class="shipping" type="checkbox" id="shipping" value="19.99"/>
    <label class="shippingcheck">19.99(Optional Shipping, will be added to total if chosen)</label>
    <br>
    <br>
    <button name="submit" type="submit" id="submit">Pay Now</button>

    <input type="hidden" name="hdwtablename" id="hdwtablename" value="1">
    <input type="hidden" name="hdwppproductname" id="hdwppproductname" value="Basic Plan $175">
    <input type="hidden" name="hdwppamount" id="hdwppamount" value="175">
    <input type="hidden" name="hdwppcurrency" id="hdwppcurrency" value="USD">
    <input type="hidden" name="hdwpplanguage" id="hdwpplanguage" value="en_US">
    <input type="hidden" name="hdwok" id="hdwok" value="http://www.topchoicedata.com/paymentmadethanks.php">
    <input type="hidden" name="hdwemail" id="hdwemail" value="mauriceflopez+gmail.com">
    <input type="hidden" name="hdwnook" id="hdwnook" value="http://">
    <input type="hidden" name="hdwactivation_email" id="hdwactivation_email" value="email">
    <input type="hidden" name="plan" id="plan" value="$175">
    <input type="hidden" name="shippingchoosen" id="shippingchoosen" value="">
    <input type="hidden" name="shippingnumber" id="shippingnumber" value=""> -----**TAKE NOTICE HERE**
  </form>

Below is a link to a picture of my backend when the customers info is saved after submitting their credentials in the 175 form(Info collected at this point is only for form submission and not paypal info).

Backend with customer info from database

As you can see, the person submitted his email("thisisatestemail2016@gmail.com) in the form, and is now in the row, at this point the shippingorder field is empty which is what i want. I now want to fill the "shipping order" field with info, which would then trigger an email to the person's email in that row. I wrote some code hoping that it would work, and placed it at the bottom of the PPPaymentForm/PPPaymentForm.php file, but nothing is working. Below is the code i added to the bottom of the PPPaymentForm.php, with section 2 being the section where i was trying to send an email if the shippingorder field had data put into it. Im guessing i may need some sort of update script in the php, but this is where i am lost

Any help would be greatly greatly appreciated.

<?php
  $connect = mysql_connect("localhost", "username", "password") or die ("Cannot connect");
  mysql_select_db("database") or die("Cannot select database");



  /*SECTION 2*/

 /*
 * Checks form field for shipping number, then where shipping has email, send email to recipient     
*/

$results = mysql_query("SELECT shippingnumber FROM topchoiceform WHERE email=$email");
if(mysqli_num_rows($result) >0){
    $row = mysqli_fetch_assoc($result);
    if ($_POST['shippingnumber']==$row['shippingnumber']) {

       $email = $_POST['email'];
       $subject = "Product has been shipped";
       $message='Your product has been shipped';

       foreach($email as $email){
        mail($email,$subject, $message);
       }
    }

}




/*SECTION 3*/

/*
 * Checks if the shipping number exists and look for email in that row which belongs to that shipping number to send email out.
 */


   $sql = "SELECT COUNT(*) FROM topchoiceform WHERE shippingnumber = '$shippingnumber' AND '$shippingnumber' MATCHES $email";



    $result = mysql_query($sql)or die('Could not find member: ' . mysql_error());

    if(mysqli_num_rows($result) >0){
        $row = mysqli_fetch_assoc($result);
        if($shippingnumber = $row['shippingnumber']){
             echo "It exists";
}            
    }else{
        echo "No matching shipping number found upon sql call";

    }

?>

Why not just send the email when the shipping number is updated?

// In the script where you update the shippingnumber
$email = $_POST['email'];
$shippingnumber = $_POST['shippingnumber'];

mysql_query("UPDATE topchoiceform SET shippingnumber = '$shippingnumber' WHERE email = '$email'");
$subject = "Product has been shipped";
$message='Your product has been shipped';
mail($email,$subject, $message);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM