表格发送电子邮件至PHP

时间:2018-03-29 01:22:06

标签: php html forms

您好我是php的新手并且我不太确定如何执行此操作我正在尝试构建一个联系表单,该表单发送一封电子邮件,目前我对该表单的HTML有:

<section class="mbr-section form1 cid-qL6aon4aVW" id="form1-11">




<div class="container">
    <div class="row justify-content-center">
        <div class="title col-12 col-lg-8">
            <h2 class="mbr-section-title align-center pb-3 mbr-fonts-style display-2">
                MAINTENANCE FORM
            </h2>
            <h3 class="mbr-section-subtitle align-center mbr-light pb-3 mbr-fonts-style display-5">
                Request Maintenance for your unit.</h3>
        </div>
    </div>
</div>
<div class="container">
    <div class="row justify-content-center">
        <div class="media-container-column col-lg-8" data-form-type="formoid">


                <form class="mbr-form" action="feedback.php" method="post">
                    <div class="row row-sm-offset">
                        <div class="col-md-4 multi-horizontal" data-for="name">
                            <div class="form-group">
                                <label class="form-control-label mbr-fonts-style display-7" for="name-form1-11">Full Name</label>
                                <input type="text" class="form-control" name="name" data-form-field="Name" required="" placeholder="Full Name" id="name-form1-11">
                            </div>
                        </div>
                        <div class="col-md-4 multi-horizontal" data-for="email">
                            <div class="form-group">
                                <label class="form-control-label mbr-fonts-style display-7" for="email-form1-11">Email Address</label>
                                <input type="email" class="form-control" name="email" data-form-field="Email" required="" placeholder="Email" id="email-form1-11">
                            </div>
                        </div>
                        <div class="col-md-4 multi-horizontal" data-for="phone">
                            <div class="form-group">
                                <label class="form-control-label mbr-fonts-style display-7" for="phone-form1-11">Phone Number</label>
                                <input type="tel" class="form-control" name="phone" data-form-field="Phone" placeholder="Phone #" id="phone-form1-11">
                            </div>
                        </div>
                    </div>
                    <div class="form-group" data-for="message">
                        <label class="form-control-label mbr-fonts-style display-7" for="message-form1-11">Request</label>
                        <textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message" placeholder="Request" id="message-form1-11"></textarea>
                    </div>

                    <span class="input-group-btn">
                        <button href="" type="submit" class="btn btn-primary btn-form display-4">SEND FORM</button>
                    </span>
                </form>
        </div>
    </div>
</div>

我拥有的PHP是:

<?php

if (isset($_POST['submit'])){

$to="email@email.com";

$subject="Shovers.net Maintenance form submission";

$mail_from="from: ".$_POST['email']." \n";

$mail_from .="Content-Type: text/html; charset=utf-8 \n";

$message="<font size=\"2\" face=\"Verdana\"> Here is the message:<br />
".$_POST['comments']."<br />
".$_POST['name']."<br />
".$_POST['email']."</font>";

mail($mail_from,$to,$subject,$comments);

echo "Thanks!";
$TARGET = "/";

    header("Location: $TARGET");
    exit();


}else{
}
?>

我似乎无法将此发送到我的电子邮件,我不知道为什么在表单上提交它目前只是转到feedback.php页面,这是空白的,因为它只是PHP脚本。这是否需要在实际的服务器上运行才能运行,还是可以运行xampp和apache / mysql?如果不是我需要做什么才能使其正常工作?

此外,我还试图让它重新加载/停留在同一页面上,但弹出一条验证消息,我为此做错了什么?

任何帮助表示赞赏!

谢谢!

0 个答案:

没有答案