繁体   English   中英

发送联系表不起作用

[英]Send Contact Form not Working

我遵循了有关发送联系表单的简单教程,但是似乎不起作用。 请有人帮忙。

表格如下:

<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,人们可以看到它。

将您的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”

鉴于您的输入已相应命名,请尝试以下操作:

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

您实际上从不掌握所有职位价值。

将其作为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";
}
?>

另外,您在回声中拼写错误“ received”,因此我解决了拼写错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM