Php 将电子邮件脚本重定向到网页

Php 将电子邮件脚本重定向到网页,php,email,send,Php,Email,Send,我目前有下面的email/db脚本可以正常工作,但重定向似乎不起作用。而不是重定向到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_

我目前有下面的email/db脚本可以正常工作,但重定向似乎不起作用。而不是重定向到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"; 
}
?>
尝试以下代码:

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

header("Location: http://www.url.co.uk");

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

Apache/PHP日志文件中是否有任何错误?您的代码有一些问题……在将POST变量插入数据库之前,您肯定应该在POST变量上使用mysql\u real\u escape\u字符串。您应该转到mysqli,因为mysql_uu函数已被弃用。谢谢,但这给了我一个错误,说明未选择任何数据库。这需要添加到哪里?谢谢,但是它只给了我一个php页面的空白页面,没有重定向。
<?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"; 
}
?>