PHP联系表单错误

时间:2012-03-16 16:03:39

标签: php

为我的联系表格提供以下内容,我只建议不发送...

我曾尝试将结果打印到它所执行的浏览器但由于某种原因它不会发送,有人能看到语法错误吗?

<?php 

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$addr = $_POST['addr'];
$postcode = $_POST['postcode'];
$landline = $_POST['landline'];
$mob = $_POST['mob'];
$carw = $_POST['carw'];
$depo = $_POST['depo'];
$marsta = $_POST['marsta'];
$ressta = $_POST['ressta'];
$to = "liam@.co.uk";

    //begin of HTML message
    $message = "
  From : $name $lname,
  Email: $email,
  Address: $addr $postcode,
  Landline: $landline,
  Mobile: $mob,
  Car Wanted: $carw,
  Deposit Available: $depo,
  Marital Status: $marsta,
  Residential Status: $ressta";
   //end of message

    // To send the HTML mail we need to set the Content-type header.
    $headers = "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
    $headers  .= "From: Website Enquiry";




if (isset($name))
{
       // now lets send the email.
   mail($to, $subject, $message, $headers);

header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');

} else {header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');}

?> 

2 个答案:

答案 0 :(得分:3)

它不起作用的原因是你正在检查是否设置了$name,而显然不是。{你有一个$fname

答案 1 :(得分:2)

请勿使用rn,请使用\r\n

网址对您的Location:标头数据进行编码。网址没有空格。

另外,请注意,并非每个人都可以阅读HTML电子邮件。发送除HTML版本之外的文本版本。

最后,您可能不希望发送此类开放式电子邮件,因为垃圾邮件发送者可以使用此脚本轻松使用该邮件。