0

我目前有以下工作正常的电子邮件/数据库脚本,但重定向似乎不起作用。而不是重定向到 url 它只是显示空白 php 页面。我怎样才能解决这个问题?

<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("register", $con);
$sql="INSERT INTO register_interest (Name, Email, Message, Website)

VALUES ('$_POST[Name]', '$_POST[Email]', '$_POST[Message]', '$_POST[Website]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
 mysql_close($con);
$to = "email";
$subject = "Interest";
$email = $_POST['Email'] ;
$message = $_POST['Message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;

if ($sent) {
  header("Location: http://www.url.co.uk"); 
  exit();
} else {
  print "We encountered an error sending your email"; 
}
?>
4

3 回答 3

0
<?php
$con = mysqli_connect("localhost","user","pass","register");
if (mysqli_connect_errno())
{
    die('Could not connect: ' . mysqli_connect_error());
}
$name = mysqli_real_escape_string($con, $_POST['Name']);
$email = mysqli_real_escape_string($con, $_POST['Email']);
$message = mysqli_real_escape_string($con, $_POST['Message']);
$website = mysqli_real_escape_string($con, $_POST['Website']);

$sql = "INSERT INTO register_interest (Name, Email, Message, Website)
VALUES ('$name', '$email', '$message', '$website')";

if (!mysqli_query($con, $sql))
{
    die('Error: ' . mysqli_error($con));
}
mysqli_close($con);

$to = "email@address.com";
$subject = "Interest";
$email = $_POST['Email'] ;
$message = $_POST['Message'] ;
$headers = "From: $email\n";
$sent = mail($to, $subject, $message, $headers) ;

if ($sent) {
  header("Location: http://www.url.co.uk"); 
  exit();
} else {
  print "We encountered an error sending your email"; 
}
?>
于 2013-07-12T13:49:31.290 回答
0

试试这个代码:

if(!$sent){
    print "We encountered an error sending your email";
    exit;
}

header("Location: http://www.url.co.uk");
于 2013-07-12T13:47:49.773 回答
0

检查在开始 PHP 标记之前是否有任何空行),那么 header 指令将不起作用。

于 2013-07-12T14:27:25.573 回答