【问题标题】:How to send email trigger notification to specific email within row when field is updated/inputted with data当字段更新/输入数据时,如何将电子邮件触发通知发送到行内的特定电子邮件
【发布时间】:2016-10-28 02:05:41
【问题描述】:

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

所以我一直在努力解决这个问题,需要一些指导和帮助。简而言之,我需要能够在数据库或自定义后端填写一个空字段(字段称为“shippingnumber”),然后触发自定义电子邮件通知到同一行中的人员电子邮件。这是我到目前为止得到的。我们将使用电子邮件“thisisatestemail2016@gmail.com”作为示例。这是该人将提交到下面表格中的电子邮件,也是当“shippingnumber”字段输入数据时将收到电子邮件通知的同一电子邮件。

所以我创建了一个订单 (http://www.topchoicedata.com/175.php#175)。在这里,我们有 5 个字段,客户可以输入额外运费选项。当用户提交时,它会将他们带到贝宝付款页面。此时,来自 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 表单中提交凭据后保存时(此时收集的信息仅用于表单提交,而不是贝宝信息)。

Backend with customer info from database

如您所见,此人在表单中提交了他的电子邮件(“thisisatestemail2016@gmail.com),现在在行中,此时 shippingorder 字段为空,这就是我想要的。我现在想要用信息填写“运输订单”字段,然后会触发一封电子邮件到该行中的人的电子邮件。我写了一些代码希望它可以工作,并将其放在 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";

    }

?>

【问题讨论】:

    标签: php forms email paypal triggers


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-28
      • 2014-05-22
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 2013-12-02
      • 2019-01-28
      • 1970-01-01
      相关资源
      最近更新 更多