将表单提交到电子邮件并重定向不起作用
Posted
技术标签:
【中文标题】将表单提交到电子邮件并重定向不起作用【英文标题】:Submitting Form To Email and Redirecting Not Working 【发布时间】:2015-08-01 15:08:13 【问题描述】:我需要有关此 php 代码的帮助...它不会重定向到指定的 url
<?php
if(isset($_POST['submit']))
$to = "email@domain.com"; // this is your Email address
$firstName = $_POST['$inf_tTzSYWEgQfQ4dJf9'];
$lastName = $_POST['lastName'];
$phoneNumber = $_POST['phoneNumber'];
$company = $_POST['company'];
$addressLine1 = $_POST['addressLine1'];
$addressLine2 = $_POST['addressLine2'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$emailAddress = $_POST['emailAddress'];
$subject = "New Order - " . $firstName . " " . $lastName;
$body = "First Name: $firstName\n Last Name: $lastName\n Phone Number: $phoneNumber\n Company: $company\n Address Line 1: $addressLine1 \n Address Line 2: $addressLine2 \n City: $city\n State: $state\n Country: $country\n Email Address:$emailAddress";
header('Location: http://***.com/');
?>
这是 html 表单
<form method="post" name="orderForm" id="orderForm" action="ordersubmithandler.php">
<div id="header">
<div class="CUSTOM_HTML">
<div id="customHeader">
</div>
</div>
<div id="IMAGE">
<div id="companyLogoTopBanner">
<img src="orderpage_files/jp126-666e1bad-894a-41bd-9d30-be234e2bf638-v2.png">
</div>
</div>
</div>
<div id="content">
<input id="previewMode" name="previewMode" type="hidden" value="false">
<div id="ORDER_FORM_PRODUCT_LIST">
<table class="viewCart tabular grid">
<tbody>
<tr>
<th class="leftAlign">Products</th>
<th></th>
<th class="rightAlign priceCell">Price</th>
<th class="centerAlign qtyCell">Quantity</th>
<th class="rightAlign priceCell">Total</th>
</tr>
<tr>
<td colspan="2" class="productCell">
<h1>Lorem ip</h1>
<p class="productDescription">Lorem ipLorem ipLorem ipLorem ipLorem ipLorem ipLorem ipLorem ip</p>
<span class="subscriptionPlan">One Time Payment of $80.00</span>
</td>
<td class="rightAlign priceCell">
<span class="price">$80.00</span>
</td>
<td class="centerAlign qtyCell">1 </td>
<td class="rightAlign priceCell">$80.00</td>
</tr>
<tr class="subtotal">
<td class="leftAlign"><span class="totalPrice">Subtotal</span></td>
<td co="" colspan="2"></td>
<td class="qtyCell"></td>
<td class="rightAlign priceCell"><span class="priceBold">$80.00</span></td>
</tr>
</tbody>
</table>
</div>
<div id="CUSTOM_HTML">
<div id="productInformation">
<input name="" type="checkbox" checked="yes" value=""> <font color="black"><b> I understand and agree I will be charged one payment today of $80.00 as FULL payment for the product. </b></font><b> <br> <br>
</b></div>
</div>
<b>
<div id="UP_SELLS">
</div>
<div id="ORDER_FORM_BILLING_ENTRY">
<link href="./orderpage_files/anti_spam.jsp" rel="stylesheet" type="text/css">
<script type="text/javascript">(function()
var styleArray = ["/css/anti_spam.jsp"];
if (window.Infusion)
Infusion.stylesLoaded(styleArray);
else if (window.InfusionStyles)
window.InfusionStyles.concat(styleArray);
else
window.InfusionStyles = styleArray;
)();</script>
<div id="orderFormBillingEntry">
<table class="billingTable tabular grid">
<tbody>
<tr>
<th colspan="2" class="leftAlign">Billing Information</th>
</tr>
<tr>
<td class="rightAlignTop"><label class="checkoutLabel">* First Name</label></td>
<td>
<input class="regula-validation checkoutTop" data-constraints="@Required(label="First Name", groups=[customer])" id="firstName" name="firstName" size="10" type="text">
<input class="inf_a2f0ec38ba2014366540402764cde59e" id="inf_tTzSYWEgQfQ4dJf9" name="inf_tTzSYWEgQfQ4dJf9" type="text">
</td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">* Last Name</label></td>
<td><input class="regula-validation checkout" data-constraints="@Required(label="Last Name", groups=[customer])" id="lastName" name="lastName" size="12" type="text"></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">Company Name</label></td>
<td><input class="checkout" id="company" name="company" size="25" type="text"></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">* Address - Line 1</label></td>
<td><input class="regula-validation checkout" data-constraints="@Required(label="Address - Line 1", groups=[customer])" id="addressLine1" name="addressLine1" size="25" type="text"></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">Address - Line 2</label></td>
<td><input class="checkout" id="addressLine2" name="addressLine2" size="25" type="text"></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">* City</label></td>
<td><input class="regula-validation checkout" data-constraints="@Required(label="City", groups=[customer])" id="city" name="city" size="15" type="text"></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel"><div id="stateRequired">* State</div></label></td>
<td><select class="regula-validation checkout" data-constraints="@StateRequiredForSpecificCountries(countryFieldName="country", label="State", groups=[customer])" id="state" name="state" data-on="Component.Select"><option value="Lagos">Lagos</option></select></td>
</tr>
<tr>
<td class="rightAlign"><label class="checkoutLabel">* Country</label></td>
<td><select class="regula-validation checkout" data-constraints="@Required(label="Billing Country", groups=[customer])" id="country" name="country" data-on="Component.Select"><option value="Nigeria">Nigeria</option></select></td>
</tr>
<tr>
<td class="rightAlign">* Phone Number</td>
<td><input class="regula-validation checkout" data-constraints="@Required(label="Phone Number", groups=[customer])" id="phoneNumber" name="phoneNumber" size="25" type="text"></td>
</tr>
<tr>
<td class="rightAlign">* Email Address</td>
<td><input class="regula-validation checkoutBottom" data-constraints="@Required(label="Email Address", groups=[customer]) @Email(label="Email Address", groups=[customer])" id="emailAddress" name="emailAddress" size="15" type="text"></td>
</tr>
<tr>
<td> </td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">jQuery(document).ready(function()
var $country = jQuery('#country');
if ($country.val() == 'United States' || $country.val() == 'Canada')
jQuery('#stateRequired').html('* State');
if ($country.length > 0 && "SELECT" == $country.get(0).tagName)
$country.change(function()
if ($country.val() == 'United States' || $country.val() == 'Canada')
jQuery('#stateRequired').html('* State');
else
jQuery('#stateRequired').html('State');
);
);
jQuery('#addressLine1, #city, #zipCode, #country, #state').change(function()
Infusion.Ecomm.OrderForms.submitFormUponChangeOnBilling('orderForm', 'Profit-Academy-2015--Payment-Plan', 'RENDER_ORDER_FORM');
);</script>
</div>
<div id="ORDER_FORM_SHIPPING_ENTRY">
<div id="orderFormShippingEntry">
</div>
</div>
<div id="SHIPPING_OPTIONS">
<div id="shippingOptionsContainer">
</div>
</div>
<div id="PAYMENT_PLANS">
</div>
<div id="ORDER_FORM_SUMMARY">
<table class="orderSummary tabular grid">
<tbody>
<tr>
<th class="leftAlign">Summary Of What You Are Getting</th>
<th class="rightAlign"></th>
</tr>
<tr>
<td colspan="2">
<img src="bonus.png">
</td>
</tr>
<tr>
<th class="leftAlign">Order Summary</th>
<th class="rightAlign"></th>
</tr>
<tr>
<td class="listCell">Subtotal</td>
<td class="rightAlign">$80.00</td>
</tr>
<tr>
<td class="subtotal">Total Due</td>
<td class="rightAlign subtotal">$80.00</td>
</tr>
</tbody>
</table>
</div>
<div id="PAYMENT_SELECTION">
<table class="paymentMethodTable tabular grid">
<tbody>
<tr>
<td>
<button type="submit" style="align-content: center"><img src="bbbbbb.png" ></button>
</td>
</tr>
</tbody>
</table>
</div>
</b>
</div>
<b>
<br clear="all">
<div id="footer">
<div id="CUSTOM_HTML">
<div id="customFooter">
<!--<center><img src="./orderpage_files/payment-logos.jpg" ></center> --><br>
<center>
<font color="red">NOTICE: <i></i></font><i><font color="black"><b>Lorem ipsum, Please contact us at: <a href="mailto:mail@mail.com">mail@mail.com</a></b></font></i><b>
<br> <br>
<font color="black"><b>Copyright © . All rights reserved.<br></b></font>
<br>
<br>
<font color="black"><b> NEED HELP? Please contact us at: <a href="mailto:mail@mail.com">mail@mail.com</a> </b></font></b>
</center>
<b><font color="black"></font></b>
</div>
<b><font color="black"></font></b>
</div>
<b><font color="black"></font></b>
</div>
<b><font color="black"></font></b>
</b>
</form>
我尝试了多次编辑,但无法弄清楚代码有什么问题。
需要帮助...谢谢!
非常感谢您的帮助:)
【问题讨论】:
您从标题上方删除了回声,这就是我关闭问题的原因,但未能将其标记为编辑。现在您将需要发布您的 HTML 表单,因为这很可能是问题所在。这样做,我将重新提出问题。 那么这不清楚$_POST['$inf_tTzSYWEgQfQ4dJf9'];
与数组中的$
。我敢打赌它不会做任何事情,主要是因为if(isset($_POST['submit']))
- 所以再次发布您的 HTML 表单。
您好,我已经包含了来自...的 HTML,您现在可以看一下吗?谢谢。
$_POST['$inf_tTzSYWEgQfQ4dJf9'];只是字段的名称
这里最大的问题是if(isset($_POST['submit']))...
内部没有执行任何操作,因为您没有带有 name 属性的提交按钮。 IE。 name="submit"
。将错误报告添加到您打开 PHP 标记之后的文件顶部,例如 <?php error_reporting(E_ALL); ini_set('display_errors', 1);
,然后是其余代码,以查看它是否产生任何结果。
【参考方案1】:
它可能无法正常工作,因为您的按钮没有被称为“提交”
<button type="submit" style="align-content: center">
尝试将 name = "submit" 放在那里..
另外,您总是可以在 php 代码中进行一些调试,因此它会回显出它检查值的操作是您所想的。此外,您设置了一堆变量并且什么都不做 - 不是吗?是指实际发送电子邮件?
【讨论】:
which is what I said... 和 the debug stuff too...【参考方案2】:$_POST['$inf_tTzSYWEgQfQ4dJf9'];
和数组中的$
不应该存在,因为它被视为另一个变量。
然后你的提交按钮没有被命名,这就是你的代码没有在第一个条件语句中执行的原因。
您需要为其添加名称属性,如name="submit"
。
【讨论】:
以上是关于将表单提交到电子邮件并重定向不起作用的主要内容,如果未能解决你的问题,请参考以下文章