我不知道我做错了什么......我想提交一个php表单然后我想重定向到我的网址之外的另一个页面。这是我的代码,我是这方面的初学者,所以非常感谢任何帮助。
代码:
<?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"));
?>
答案 0 :(得分:0)
这样做的正确方法是:
if(mail($to,$email_subject,$email_body,$headers)){
header("Location: http://example.com/thankyou.html");
exit();
}else{
return false;
}