【问题标题】:How to generate email trigger to specific email when particular field in database is entered输入数据库中的特定字段时如何为特定电子邮件生成电子邮件触发器
【发布时间】:2016-07-28 19:11:28
【问题描述】:

我希望得到一些帮助。

我想在特定字段中有数据时向特定客户电子邮件发送电子邮件通知。

我已经构建了一个表单,其中客户被重定向到贝宝页面,此时,用户的信息被输入到数据库中。

然后我可以在管理网页上编辑信息,所有信息都从数据库中回显。我要更新的字段名为“shippingnumber”,在客户提交时为空白。当我们在此字段中输入一个数字时,我希望它生成一封电子邮件,然后将其发送到同一行中关联的电子邮件,通知他们订单已发货等,在这种情况下例如“wendybrown@hotmail.com . 下面是我的数据库从 mysql 数据库回显到网页的图片的链接,红色圆圈是我想输入数字的字段,蓝色圆圈是我需要接收一次电子邮件通知的电子邮件shippingnumber 字段输入了一个数字

Database image

我已经对此问题进行了一些研究并亲自尝试过,但我无法弄清楚这一点,也无法找到适合我需求的解决方案。请原谅我,因为我是新手,并希望获得一些关于如何实现这一目标的指导。下面是我的 paypalform 的 html 页面,在这种情况下,产品价值 325 美元。

谢谢

HTML:

<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" 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 choosen)</label>
    <br>
    <br>
    <button name="submit" type="submit">Pay Now</button>
    <input type="hidden" name="hdwtablename" id="hdwtablename" value="1">
    <input type="hidden" name="hdwppproductname" id="hdwppproductname" value="Bronze Plan 325">
    <input type="hidden" name="hdwppamount" id="hdwppamount" value="325">
    <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="">
    <input type="hidden" name="hdwemail" id="hdwemail" value="something+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="$325">
    <input type="hidden" name="shippingchoosen" id="shippingchoosen" value="">
    <input type="hidden" name="shippingnumber" id="shippingnumber" value="">
  </form>

嘿,马斯卡连特 感谢您的回复。我使用 hotdreamweaver 脚本中的一个脚本,称为 paypal 付款表单。(www.hotdreamweaver.com/paypal-payment-form)所以它的工作方式是将页面中的 html 表单转换为 paypal 表单,从而生成一个名为“PPPaymentForm/PPPaymentForm.php”的文件夹下面是一个带有php的记事本文档的链接。

http://www.cedarpublishing.com/phpcode.txt

更新

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

     */

     $result = mysql_query("SELECT * FROM table");
     $shippingnumber = $_POST['shippingnumber'];
     $email = $_POST['email'];


     if (isset($_POST['submit'])) {
if(mysqli_num_rows($result) >0)
    $row = mysqli_fetch_assoc($result);
    $shippingnumber = $row['shippingnumber'];
    if(isset($_POST['shippingnumber'])==$row['shippingnumber']){



       $to = $_POST['email'];
       $first = $_POST['firstname'];
       $last = $_POST['lastname'];
       $subject = "Product has been shipped";
       $subject .= $last; 
       $subject .= ', ';
       $subject .= $first;
       $subject .= ')';

       $message .= 'Company Name: ' . $_POST['companyname'];
       $message = 'First Name: ' . $_POST['firstname'] . "\r\n\r\n";
       $message .= 'Last Name: ' . $_POST['lastname'] . "\r\n\r\n";
       $message .= 'Address Line 1: ' . $_POST['address'] . "\r\n\r\n";
       $message .= 'Email: ' . $_POST['email'] . "\r\n\r\n";



       $headers = "From: myownemail@gmail.com\r\n";
       $headers .= 'Content-Type: text/plain; charset=utf-8';


$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email) {
    $headers .= "\r\nReply-To: $email";
}

$success = mail($to, $subject, $message, $headers);
}

}


/*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";

    }

?>

【问题讨论】:

  • 您需要更好地描述您的代码,因为在这种情况下,HTML 对我们没有多大帮助。我可以看到您正在将此 HTML 文档提交到 PHP 页面,我们可以看看吗?任何电子邮件发送都需要在服务器端完成。
  • 嘿马斯卡连特感谢您的回复。我使用 hotdreamweaver 脚本中的一个脚本,称为 paypal 付款表单。(www.hotdreamweaver.com/paypal-payment-form)所以它的工作方式是将页面中的 html 表单转换为 paypal 表单,从而生成一个名为“PPPaymentForm/PPPaymentForm.php 的文件夹下面是一个带有 php 的记事本文档的链接。cedarpublishing.com/phpcode.txt
  • @MannySmith - 请停止尝试使用更新的代码编辑答案。这应该添加到问题中,而不是某人的答案中。
  • 嗨,andrewsi,我很抱歉,这是我第一次使用 stackoverflow。

标签: javascript html mysql email triggers


【解决方案1】:
<?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     

     */

     $result = mysql_query("SELECT * FROM table");
     //$shippingnumber = $_POST['shippingnumber']; dont assign this value yet
     //$email = $_POST['email']; assign this after you check to see if $_POST is set

    //You can do this two proven ways....one is to get 1 result with the proper query. The other to loop through the records in the database to check for the number.
     //here it loops through all the records

     if (isset($_POST['submit'])) {
         $array;
         $shippingnumber = $row['shippingnumber'];
         $email = $_POST['email'];
        if(mysqli_num_rows($result) >0){
            while($row = mysqli_fetch_assoc($result)){
            // This will return multiple rows
            //http://stackoverflow.com/questions/26701305/return-multiple-values-from-a-function-using-mysqli-fetch-assoc
            if($row['shippingnumber'] == $shippingnumber){
                //record containing the shipping number is found.
                $array[] = $row;
            }
        }

       $to = $array['email']; // email = the name of the column in your database. 
       $first = $_POST['firstname'];
       $last = $_POST['lastname'];
       $subject = "Product has been shipped";
       $subject .= $last; 
       $subject .= ', ';
       $subject .= $first;
       $subject .= ')';

       $message .= 'Company Name: ' . $_POST['companyname'];
       $message = 'First Name: ' . $_POST['firstname'] . "\r\n\r\n";
       $message .= 'Last Name: ' . $_POST['lastname'] . "\r\n\r\n";
       $message .= 'Address Line 1: ' . $_POST['address'] . "\r\n\r\n";
       $message .= 'Email: ' . $_POST['email'] . "\r\n\r\n";

       $headers = "From: myownemail@yourdomain.com\r\n"; 
       ////email on your domain. NOT SURE if you even need an email...
       ////but headers are touchy, Usually web based applications can only operate WITHIN its own DOMAIN
       $headers .= 'Content-Type: text/plain; charset=utf-8';


$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email) {
    $headers .= "\r\nReply-To: $email";
}

$success = mail($to, $subject, $message, $headers);
}

}


/*SECTION 3*/

    //NOTE: This is basically what we did in part 1 without sending anything except were finding the shipping number exactly as it is in the databse and pulling the whole record(all columns)

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


    //this isnt going to work,
    //$sql = "SELECT COUNT(*) FROM topchoiceform WHERE shippingnumber = '$shippingnumber' AND '$shippingnumber' MATCHES $email";
    $sql = "SELECT * FROM topchoiceform WHERE shippingnumber = '$shippingnumber'"; 
//select one record where the shipping number matches
//now you dont need to loop this time

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

    if(mysqli_num_rows($result) >0){ //if this is > 0 than the shippingnumber exists
        $row = mysqli_fetch_assoc($result);
        if($shippingnumber == $row['shippingnumber']){
             //echo "It exists";
             $email = $row['email']; 
             $firstname = $row['firstname'];
             $lastname = $row['lastname'];
             //ect...remember the names inside $row['name'] is the same thing in your database

             //enter code to send mail
}            
    }else{
        echo "No matching shipping number found upon sql call";

    }

?>

【讨论】:

  • 我为你填了一些空白,希望对你有帮助。
  • 嘿,杰克,到目前为止看起来不错。但是,我们实际上不需要生成数字。处理表单时,我们实际上希望 shippingnumber 字段为空白。在客户付款后,我们实际上会收到来自 Fedex 或 ups 的运输号码。当我们得到那个号码时,我们会用那个号码填充那个 shippingorder 字段。然后它将电子邮件发送给该特定客户。那么对于 html 部分,我会使用我之前的 html 代码吗?
  • 嘿杰克,很遗憾,当我在 shippingnumber 字段中输入数字时,我无法收到电子邮件。我已经详细概述了我在代码中遇到的问题。感谢您的帮助:)
  • 您是否在 cpanel 中创建了要发送的电子邮件?
  • 嗨 Jack 不,电子邮件已经在 gmail(thisisatestemail2016@gmail.com) 中创建,所以当用户在订单中提交它时,它会被输入到名为“email”的字段中。因此,当我在“shippingorder”字段中输入一个数字时,它会将电子邮件通知发送到 thisisatestemail2016@gmail.com
猜你喜欢
  • 1970-01-01
  • 2011-08-29
  • 1970-01-01
  • 1970-01-01
  • 2013-12-02
  • 2012-11-07
  • 2016-11-06
  • 2020-08-10
  • 1970-01-01
相关资源
最近更新 更多