发送联系表格不起作用

时间:2013-03-02 21:03:18

标签: php

我已经按照发送联系表单的简单教程,但似乎无法正常工作。请有人帮忙。

以下表格:

<table width="400" border="0" cellspacing="1" cellpadding="0" align="center">
    <tbody>
        <tr>
            <td>
                <form action="send.php" method="post" name="form1">
                    <table width="100%" border="0" cellspacing="1" cellpadding="3">
                        <tbody>
                            <tr>
                                <td width="16%">Name</td>
                                <td width="2%">:</td>
                                <td width="82%"><input id="Name" type="text" name="Name" size="50" /></td>
                            </tr>
                            <tr>
                                <td>Email</td>
                                <td>:</td>
                                <td><input id="customer_mail" type="text" name="customer_mail" size="50" /></td>
                            </tr>
                            <tr>
                                <td>Subject</td>
                                <td>:</td>
                                <td><input id="Subject" type="text" name="Subject" size="50" /></td>
                            </tr>
                            <tr>
                                <td>Detail</td>
                                <td>:</td>
                                <td><textarea id="detail" cols="50" name="detail" rows="4"></textarea></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td></td>
                                <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </td>
        </tr>
    </tbody>
</table>

这是我的PHP:

<?php
    $to ='kirsty.harris1985@gmail.com';

    $header="from: $name <$mail_from>";

    $mail_from="$customer_mail";
    $Subject="$Subject";
    $detail="$detail";

    $send_contact=mail($to,$header,$Subject,$detail);

    if($send_contact){
        echo "We've recived your contact information";
    } else {
        echo "ERROR";
    }
?>

这是错误:

服务器错误 检索http://nqmedia.co.uk/send_contact.php时网站遇到错误。它可能已关闭以进行维护或配置不正确。 以下是一些建议: 稍后重新载入此网页。 HTTP错误500(内部服务器错误):服务器尝试完成请求时遇到意外情况。

此外,该网站还有www.nqmedia.co.uk供人们查看。

3 个答案:

答案 0 :(得分:0)

将您的PHP更改为以下内容:

<?php
    $to ='kirsty.harris1985@gmail.com';
    $name = $_POST['name'];
    $customer_mail = $_POST['customer_mail'];
    $Subject = $_POST['Subject'];
    $detail = $_POST['detail'];

    $header="From: $name <$customer_mail>";

    $send_contact=mail($to,$Subject,$detail,$header);

    if($send_contact){
        echo "We've recived your contact information";
    } else {
        echo "ERROR";
    }

?>
  1. 没有正确定义变量,您需要使用$_POST来检索表单中的值。

  2. $mail_from(现在$customer_mail)在定义之前就已使用过。

  3. mail()函数中使用的参数使用顺序错误。查看http://php.net/manual/en/function.mail.php

  4. 检查表单上的action属性。它说“send.php”,但错误显示“send_contact.php”

答案 1 :(得分:0)

鉴于您的输入已相应命名 试试这个:

$name = $_POST['Name'];
$mail_from = $_POST['customer_mail'];
$header = "from: $name <$mail_from>";
$Subject = $_POST['Subject'];
$detail = $_POST['detail'];

答案 2 :(得分:0)

你永远不会抓住所有的帖子值。

将此代码设为send.php:

<?php 
$name = $_POST['Name'];
$mail_from = $_POST['customer_mail'];
$subject = $_POST['Name'];
$body = $_POST['detail'];

$to ='kirsty.harris1985@gmail.com';

$header="from: $name <$mail_from>";

$send_contact=mail($to,$Subject,$body,$header);

if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>

另外,你拼错了#34;收到&#34;你的回音,所以我修正了拼写错误。