如何获得联系表格

时间:2016-05-05 02:17:30

标签: php html

大家好我是php的新手,但到目前为止我都在努力。我在html中创建了一个简单的表单:

<div class="modal fade" id="contact" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <form class="form-horizontal" role="form" method ="post">
            <div class="modal-header">
                <h4>Contact:</h4>
            </div>

            <div class="modal-body">
                <div class="form-group">
                    <label for="contact-name" class="col-sm-2 control-label">Name</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="contact-name" placeholder="First & Last Name">
                    </div>
                </div>
                <div class="form-group">
                    <label for="contact-email" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" id="contact-email" placeholder="example@sussex.ac.uk">
                    </div>
                </div>

                <div class="form-group">
                    <label for="contact-message" id ="contact-message" class="col-sm-2 control-label">Message</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" rows="6"></textarea>
                    </div>
                </div>



            </div>

            <div class="modal-footer">
                <a class="btn btn-default" data-dismiss="modal">Close</a>
                <button type="submit1" id ="workinghere1" class="btn btn-warning" onclick ="alert('Email has been sent')">Send</button>
            </div>
        </form>
    </div>
</div>

然后为它创建了一个简单的PHP脚本:

<?php
f(isset($_POST['workinghere'])){
    $n = $_POST['contact-name'];
    $e = $_POST['contact-email'];
    $m = $_POST['contact-message'];

    $to = "*****************";
    $subject = "WEB 3d";
    $header = $e;
    $server = "smtp.live.com";
    $body = $m;
    mail($to, $subject, $body, $header);
}
?>

然而由于某种原因我不认为PHP脚本正在工作,因为根本没有电子邮件发送到我的地址,我不知道该怎么做,任何有关此问题的帮助都会很棒。

谢谢

2 个答案:

答案 0 :(得分:1)

起始地址需要以“From:someone@somewhere.com”作为前缀,因此以下内容应该有效。此外,您使用PHP读取的所有输入都需要具有名称属性。

if(isset($_POST['workinghere'])){
    $n = $_POST['contact-name'];
    $e = "From: ".$_POST['contact-email']."\r\n";
    $m = $_POST['contact-message'];

    $to = "*****************";
    $subject = "WEB 3d";
    $header = $e;
    $server = "smtp.live.com";
    $body = $m;
    mail($to, $subject, $body, $header);
}

<div class="modal fade" id="contact" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <form class="form-horizontal" role="form" method ="post">
            <div class="modal-header">
                <h4>Contact:</h4>
            </div>

            <div class="modal-body">
                <div class="form-group">
                    <label for="contact-name" class="col-sm-2 control-label">Name</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="contact-name" id="contact-name" placeholder="First & Last Name">
                    </div>
                </div>
                <div class="form-group">
                    <label for="contact-email" class="col-sm-2 control-label">Email</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" name="contact-email" id="contact-email" placeholder="example@sussex.ac.uk">
                    </div>
                </div>

                <div class="form-group">
                    <label for="contact-message" id ="contact-message" class="col-sm-2 control-label">Message</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" rows="6" name="contact-message"></textarea>
                    </div>
                </div>



            </div>

            <div class="modal-footer">
                <a class="btn btn-default" data-dismiss="modal">Close</a>
                <button type="submit1" name="workinghere" id="workinghere1" class="btn btn-warning" onclick ="alert('Email has been sent')">Send</button>
            </div>
        </form>
    </div>
</div>

答案 1 :(得分:0)

<div id="containerDIV"> <div>THIS IS SOME TEXT</div> </div> #containerDIV { max-width:200px; }

你的电子邮件首先需要打开SMTP。