与我联系表格

时间:2014-07-04 05:10:37

标签: php forms email

我正在制作一个网页,我也希望与我联系。我已经下载了一个模板,其中包含字段'name','email'和'message'以及'send'按钮。我已阅读了几本指南,但表格从未发送过。

你能帮助我吗?谢谢!

我的代码:                                                                                                                                                                                                                                                                                                                         

  •                                         
  •                                                                                                                            

    1 个答案:

    答案 0 :(得分:1)

    让我在这个级别帮助你。

    假设您的联系页面是这样的

    <title>Contact Form</title>
    <table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
    <tr>
    <td><strong>Contact Form </strong></td>
    </tr>
    </table>
    <table width="200" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td><form name="form1" method="post" action="contact_ac.php">
    <table width="100%" border="0" cellspacing="1" cellpadding="3">
    <tr>
    <td>Name</td>
    <td>:</td>
    <td><input name="name" type="text" id="name" size="50"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td>:</td>
    <td><input name="cmail" type="text" size="50"></td>
    </tr>
    <tr>
    <td width="16%">Subject</td>
    <td width="2%">:</td>
    <td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
    </tr>
    <tr>
    <td>Detail</td>
    <td>:</td>
    <td><textarea name="detail" cols="50" rows="4" id="detail"></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>
    </table>
    </form>
    </td>
    </tr>
    </table>
    

    联络页面的行动

    <?php
    $name=$_POST['name'];
    $cmail=$_POST['cmail'];
    $subject=$_POST['subject'];
    $header="from: $name <$cmail";
    $to ='yourmail@yourdomain.com';
    $send_contact=mail($to,$subject,$message,$header);
    if($send_contact){
    echo "We've recived your contact information";
    }
    else {
        echo "Error Sending Mail";
        }
    ?>
    

    注意:将$to ='yourmail@yourdomain.com';替换为您的电子邮件。