我希望得到一些帮助。
我想在特定字段中放入数据时向特定客户电子邮件发送电子邮件通知。
我已经构建了一个表单,客户被重定向到paypal页面,此时,用户的信息被输入到数据库中。
然后,我可以在管理网页上编辑信息,其中所有信息都是从数据库中回显的。我要更新的字段名为“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支付表格。(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";
}
?>
答案 0 :(得分:0)
<?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";
}
?>