当字段更新/输入数据时,如何向行内的特定电子邮件发送电子邮件触发器通知

时间:2016-04-12 21:46:30

标签: php forms email paypal triggers

很抱歉听起来像是破纪录,我上周发布了一个类似的问题并取得了不错的进展,但我还需要更进一步。

所以我一直在拉着头发,需要一些指导和帮助。简而言之,我需要能够在数据库或自定义后端填写一个空字段(字段称为" shippingnumber"),然后触发自定义电子邮件通知给人员中的电子邮件。同一行。这是我到目前为止所得到的。我们将使用电子邮件" thisisatestemail2016@gmail.com"举个例子。这是此人将在下面的表单中提交的电子邮件,也是同一封电子邮件,它将在字段中收到电子邮件通知," shippingnumber"有数据。

所以我创建了一个订单(http://www.topchoicedata.com/175.php#175)。在这里,我们有5个客户输入的字段,可选择额外的运费。当用户提交时,它将把他们带到PayPal支付页面。此时,来自5个字段的人员信息已被输入到表格数据库内的新行中。当该人进一步进行支付时,其余的字段被输入,除了一个之外,该字段被称为" shippingnumber"。它位于上述表单的隐藏输入字段中。下面是$ 175表单的html代码,表单操作在名为PPPaymentForm / PPPaymentForm.php的子文件夹中完成。注意" shippingorder"输入如下表格。

<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>

以下是在我们提交了175表格中的凭据后保存客户信息时我的后端图片的链接(此时收集的信息仅用于表单提交而不是PayPal信息)。

Backend with customer info from database

正如您所看到的,该人在表单中提交了他的电子邮件(&#34; thisisatestemail2016@gmail.com),现在已经在行中,此时shippingorder字段为空,这就是我想要的。我现在想要填写&#34;运输订单&#34;带有信息的字段,然后会触发电子邮件到该行中该人员的电子邮件。我写了一些代码,希望它可以工作,并将它放在PPPaymentForm / PPPaymentForm.php文件的底部,但没有任何工作。下面是我添加到PPPaymentForm.php底部的代码,第2部分是我试图发送电子邮件的部分,如果shippingorder字段有数据放入其中。我猜我可能需要在php中使用某种更新脚本,但这就是我迷失的地方

非常感谢任何帮助。

<?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";

    }

?>

1 个答案:

答案 0 :(得分:1)

为什么不在发货号码更新时发送电子邮件?

// 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);