我希望得到一些帮助。
我想在特定字段中放入数据时,向特定客户发送电子邮件通知。
我已经建立了一个表单,在这个表单中,客户被重定向到贝宝页面,此时,用户的信息被输入到数据库中。
然后,我可以在一个管理网页上编辑信息,所有信息都会从数据库中得到响应。我想更新的字段名为"shippingnumber",在客户提交时为空。当我们在该字段中输入一个数字时,我希望它生成一封电子邮件,然后发送到同一行中关联的电子邮件,通知他们订单已经发货等,例如"wendybrown@hotmail.com.下面是一个链接,链接到我的数据库的图片,该图片被从mysql数据库中反射到一个网页上,红色圆圈是我想输入一个数字的字段,蓝色圆圈是我需要在shippingnumber字段输入数字后收到电子邮件通知的电子邮件
数据库图像
我对这件事做了一些研究,并亲自尝试过,但我无法弄清楚这一点,也无法找到适合我需求的解决方案。请原谅我,因为我是新手,希望能得到一些关于如何实现这一目标的指导。下面是我的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 payment form的脚本
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'] . "rnrn";
$message .= 'Last Name: ' . $_POST['lastname'] . "rnrn";
$message .= 'Address Line 1: ' . $_POST['address'] . "rnrn";
$message .= 'Email: ' . $_POST['email'] . "rnrn";
$headers = "From: myownemail@gmail.comrn";
$headers .= 'Content-Type: text/plain; charset=utf-8';
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if ($email) {
$headers .= "rnReply-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";
}
?>
<?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'] . "rnrn";
$message .= 'Last Name: ' . $_POST['lastname'] . "rnrn";
$message .= 'Address Line 1: ' . $_POST['address'] . "rnrn";
$message .= 'Email: ' . $_POST['email'] . "rnrn";
$headers = "From: myownemail@yourdomain.comrn";
////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 .= "rnReply-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";
}
?>