【发布时间】:2017-01-23 00:29:20
【问题描述】:
我不知道我做错了什么...我想提交一个 php 表单,然后我想重定向到我的 url 之外的另一个页面。这是我的代码,我是这方面的初学者,因此非常感谢任何帮助。
代码:
<?php
if(empty($_POST['fname1']) && strlen($_POST['fname1']) == 0 || empty($_POST['lname1']) && strlen($_POST['lname1']) == 0 || empty($_POST['email1']) && strlen($_POST['email1']) == 0 || empty($_POST['address1']) && strlen($_POST['address1']) == 0 || empty($_POST['city1']) && strlen($_POST['city1']) == 0 || empty($_POST['cel1']) && strlen($_POST['cel1']) == 0)
{
return false;
}
$fname1 = $_POST['fname1'];
$lname1 = $_POST['lname1'];
$email1 = $_POST['email1'];
$address1 = $_POST['address1'];
$city1 = $_POST['city1'];
$cel1 = $_POST['cel1'];
$veg_24176 = $_POST['veg_24176'];
$soy_24176 = $_POST['soy_24176'];
$glu_24176 = $_POST['glu_24176'];
$lac_24176 = $_POST['lac_24176'];
$chili_24176 = $_POST['chili_24176'];
$nuts_24176 = $_POST['nuts_24176'];
$choco_24176 = $_POST['choco_24176'];
$comments1 = $_POST['comments1'];
$to = 'hola@chipzcolombia.com'; // Email submissions are sent to this email
// Create email
$email_subject = "Message from NUEVA.";
$email_body = "You have received a new message. \n\n".
"Fname1: $fname1 \nLname1: $lname1 \nEmail1: $email1 \nAddress1: $address1 \nCity1: $city1 \nCel1: $cel1 \nVeg_24176: $veg_24176 \nSoy_24176: $soy_24176 \nGlu_24176: $glu_24176 \nLac_24176: $lac_24176 \nChili_24176: $chili_24176 \nNuts_24176: $nuts_24176 \nChoco_24176: $choco_24176 \nComments1: $comments1 \n";
$headers = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n";
$headers .= "From: contact@chipzcolombia.com\n";
$headers .= "Reply-To: $email1";
mail($to,$email_subject,$email_body,$headers);
return true;// Post message
ob_start();
exit(header("Location: http://example.com/thankyou.html"));
?>
【问题讨论】:
-
请发布您的代码。
-
@bfontaine 代码被锁定在编辑管道中
-
摆脱
return true! -
空检查已经通过了,为什么还要检查字符串长度?我认为您不需要为每个字段进行 2 次检查。此外,在 return true 之后编写的任何内容都将永远不会执行,因此这应该是你的最后一行。
-
您的脚本很容易受到通过
email1字段进行的head in section 攻击,其他人也可能如此。使用电子邮件库有助于避免此类问题。
标签: php form-submit url-redirection