簡體   English   中英

使用html和php的聯系表

[英]Contact form using html and php

我正在嘗試使用html和php創建聯系表單,但是當我提交表單而不是運行php文件時,它將在我的屏幕上顯示php文件。 我沒有收到任何錯誤消息。 這是我的代碼:

HTML

<div class="container">
<h1>Contact Me</h1>
<div class="well">
    <p class="lead">
        Do you have any question? Want to write for us? Please use the below contact form and send a message. I'll reply you as quick as possible.
    </p>
</div>

<div class="contact-form">
<form method="post" action="form.php" class="form-horizontal col-md-8" role="form">

    <div class="form-group">
        <label for="name" class="col-md-2">Name</label>
        <div class="col-md-10">
            <input name="name" type="text" class="form-control" id="name" placeholder="Name">
        </div>
    </div>

    <div class="form-group">
        <label for="email" class="col-md-2">Email</label>
        <div class="col-md-10">
            <input name="email" type="email" class="form-control" id="email" placeholder="Email">
        </div>
    </div>

    <div class="form-group">
        <label for="subject" class="col-md-2">Subject</label>
        <div class="col-md-10">
            <input name="subject" type="subject" class="form-control" id="subject" placeholder="Subject">
        </div>
    </div>

    <div class="form-group">
        <label for="message" class="col-md-2">Message</label>
        <div class="col-md-10">
            <textarea name = "message" class="form-control" id="message" placeholder="Message"></textarea>
        </div>
    </div>

    <label>*What is 2+2? (Anti-spam)</label>
    <input name="human" placeholder="Type Here">

    <div class="form-group">
        <div class="col-md-12 text-right">
            <button type="submit" class="btn btn-lg btn-primary">Submit your message!</button>
        </div>
    </div>
</form>

PHP

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = $_POST['email'];;
$to = 'me@mariachavez.co';
$subject = $_POST['subject'];

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

if ($_POST['submit'] && $human == '4') {
    if (mail ($to, $subject, $body, $from)) {
          echo '<p>Your message has been sent!</p>';
     } else {
    echo '<p>Something went wrong, you can send an email to me@mariachavez.co and I'll get in touch soon</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

沒有服務器,您將無法執行PHP文件,如果沒有服務器,則需要安裝一個文件,例如WAMPXAMPP

如果有,請嘗試將其重新啟動;如果沒有,請嘗試將其重新配置為執行PHP文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM