我有一个需要姓名,地址和电话号码的着陆页(http://www.interiorswithaview.com/)。在您提交带有下载的感谢页面的表单后http://www.interiorswithaview.com/ThankYou.html 我也使用javascript(见下文)。我过去使用过此模板集,我知道它有效,但现在却没有发送电子邮件。我不知道它是否过时了?请帮忙。
<script src="mail-form.js"></script>
<form method="POST" action="mailer.php" onsubmit="return ValidateRequiredFields();" name="mail">
<table width="235" height="400" border="0" bgcolor="#d1d3d4" align="center" cellpadding="0" cellspacing="0" style="font-size:13px; font-weight:bold; color:#58585b; padding:5px;">
<tbody>
<tr><td colspan="3"><img src="images/Form-header.png" width="200" height="63" alt="" align="center"/></td></tr>
<tr>
<td colspan="3">
<p align="center" style="padding:0 8px 0 8px;"><strong>Here are three informational guides to help you get started! To download these resources, just enter your information below.</strong></p>
<p>
<ul style="list-style: none; font-size: 16px; color: #d83e45;">
<li>Q & A</li>
<li>Case Study</li>
<li>Color Consultation</li>
</ul>
</p>
</td>
</tr>
<tr>
<td width="55" height="30" align="right" style="padding-right:6px;">Name:</td>
<td width="163" align="right">
<input name="Name" type="text" id="Name" size="23">
</td>
</tr>
<tr>
<td height="30" align="right" style="padding-right:6px;">Address:</td>
<td align="right"><input name="Address" type="text" id="Address" size="23"></td>
</tr>
<tr>
<td height="30" align="right" style="padding-right:6px;">Phone:</td>
<td align="right"><input name="Phone" type="text" id="Phone" size="23"></td>
</tr>
<tr>
<td height="5" align="right" style="padding-right:6px;"> </td>
<td align="right"> </td>
</tr>
<tr>
<td height="5" align="right" style="padding-right:6px;"> </td>
<td align="right"><input type="submit" name="submit" id="submit" value="Submit" /></td>
<td width="1"></td>
</tr>
</tbody>
</table>
</form>
PHP代码
<?php
if(isset($_POST['submit'])) {
$email_to = "email@gmail.com";
$subject = "New Landing Page Consult Lead";
$name_field = $_POST['Name'];
$address_field = $_POST['Address'];
$phone_field = $_POST['Phone'];
$body = "From: $name_field\n Address: $address_field\n Phone: $phone_field\n";
header('Location: ThankYou.html');
exit();
mail($to, $subject, $body, "From: $name_field");
}
else {
echo "what?";
}
?>
的JavaScript
var FormName = "mail";
var RequiredFields = "Name,Phone,Address";
function ValidateRequiredFields() {
var FieldList = RequiredFields.split(",");
var BadList = new Array();
for(var i = 0; i < FieldList.length; i++) {
var s = eval('document.' + FormName + '.' + FieldList[i] + '.value');
s = StripSpacesFromEnds(s);
if(s.length < 1) {
BadList.push(FieldList[i]);
}
}
if(BadList.length < 1) {
return true;
}
var ess = new String();
if(BadList.length > 1) {
ess = 's';
}
var message = new String('\n\nThe following field' + ess + ' are required:\n');
for(var i = 0; i < BadList.length; i++) {
message += '\n' + BadList[i];
}
alert(message);
return false;
}
function StripSpacesFromEnds(s) {
while((s.indexOf(' ',0) == 0) && (s.length> 1)) {
s = s.substring(1,s.length);
}
while((s.lastIndexOf(' ') == (s.length - 1)) && (s.length> 1)) {
s = s.substring(0,(s.length - 1));
}
if((s.indexOf(' ',0) == 0) && (s.length == 1)) {
s = '';
}
return s;
}
答案 0 :(得分:3)
将邮件放在
之后header('Location: ThankYou.html');
mail($to, $subject, $body, "From: $name_field");
exit();
答案 1 :(得分:0)
试试这个! 改变你的PHP代码!
<?php
if(isset($_POST['submit'])) {
$email_to = "email@gmail.com";
$subject = "New Landing Page Consult Lead";
$name_field = $_POST['Name'];
$address_field = $_POST['Address'];
$phone_field = $_POST['Phone'];
$body = "From: $name_field\n Address: $address_field\n Phone: $phone_field\n";
mail($to, $subject, $body, "From: $name_field");
header('Location: ThankYou.html');
exit();
}
else {
echo "what?";
}
?>