簡體   English   中英

Bootstrap PHP聯系表格

[英]Bootstrap PHP contact form

我遇到了引導PHP聯系人表格的問題。 我使用統一主題引導框架,UI已經完成,但是我不知道如何使聯系表單功能。 誰能幫我糾正一下。 這是我的網站。 http://cloudsblack.info/

HTML PART。

    <!-- Contact Section -->
<section id="contact" class="contacts-section">
    <div class="container content-lg">
        <div class="title-v1">
            <h2>Contact Us</h2>
            <p>I'm always happy to hear from you. Please contact or email me for appointment or service enquiry.</p>
        </div>

        <div class="row contacts-in">
            <div class="col-md-6 md-margin-bottom-40">
                <ul class="list-unstyled">
                    <li><i class="fa fa-home"></i> Kuala Lumpur</li>
                    <li><i class="fa fa-phone"></i> (6)016-7187764</li>
                    <li><i class="fa fa-envelope"></i> <a href="1122johnho@gmail.com">1122johnho@gmail.com</a></li>
                </ul>
            </div>

            <div class="col-md-6">
                 <form method="post" action="index.php">
                    <label>Name</label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-7 col-md-offset-0">
                            <input type="text" class="form-control">
                        </div>                
                    </div>

                    <label>Email<span class="color-red">*</span></label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-7 col-md-offset-0">
                            <input type="text" class="form-control">
                        </div>                
                    </div>

                    <label>City</label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-7 col-md-offset-0">
                            <input type="text" class="form-control">
                        </div>                
                    </div>

                    <label>Telephone</label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-7 col-md-offset-0">
                            <input type="text" class="form-control">
                        </div>                
                    </div>


                    <label>Interested</label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-7 col-md-offset-0">
                            <input type="text" class="form-control">
                        </div>                
                    </div>

                    <label>Message</label>
                    <div class="row margin-bottom-20">
                        <div class="col-md-11 col-md-offset-0">
                            <textarea rows="8" class="form-control"></textarea>
                        </div>                
                    </div>

                    <p><button type="submit" class="btn-u btn-brd btn-brd-hover btn-u-dark">Send Message</button></p>
                </form> 
            </div>
        </div>            
    </div>

這是PHP的一部分。

<?php
$Name = $_POST['name'];
$Email = $_POST['email'];
$City = $_POST['city'];
$Telephone = $_POST['telephone'];
$Interested = $_POST['interested'];
$Message = $_POST['message'];
$from = 'From: Johnhophotography.com'; 
$to = 'cloudsblack84@gmail.com'; 
$subject = 'Message from johnhophotography.com';

$body = "From: $name\n E-Mail: $email\n City: $city\n Telephone: $telephone\n Interested: $interested\n Message:\n $message";

if ($_POST['submit']) {              
    if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
} else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
} else if ($_POST['submit']) {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

謝謝 !!!

進行以下更改:

第一次更改:

在表單標簽中,只需根據服務器上的指定名稱添加名稱。

<input type="text" name="name" class="form-control">
<input type="text" name="email" class="form-control">
<input type="text" name="city" class="form-control">
<input type="text" name="telephone" class="form-control">
<input type="text" name="interested" class="form-control">
<textarea rows="8" name="message" class="form-control"></textarea>
<button type="submit" name="submit" class="btn-u btn-brd btn-brd-hover btn-u-dark">Send Message</button></p>

如果要在服務器上接收表單數據,則必須為其提供與服務器使用的名稱相同的名稱。

第二項變更:

在您的代碼中進行以下更改:

<?php
//Add this two line in your code. It reports you exact problem you are facing in PHP Code.
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

$Name = $_POST['name'];
$Email = $_POST['email'];
$City = $_POST['city'];
$Telephone = $_POST['telephone'];
$Interested = $_POST['interested'];
$Message = $_POST['message'];
$from = 'From: Johnhophotography.com'; 
$to = 'cloudsblack84@gmail.com'; 
$subject = 'Message from johnhophotography.com';

$body = "From: $name\n E-Mail: $email\n City: $city\n Telephone: $telephone\n Interested: $interested\n Message:\n $message";

if ($_POST['submit']) {              
    if (mail ($to, $subject, $body, $from)) { 
        echo '<p>Your message has been sent!</p>';
    } else { 
        echo '<p>Something went wrong, go back and try again!</p>'; 
    } 
}
else
{
    echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>

首先,在所有輸入字段和提交按鈕中添加一個“名稱”屬性。

...然后將您的PHP更改為以下內容:

<?php

//get parameters
$name = $_POST['name'];
$email = $_POST['email'];
$city = $_POST['city'];
$telephone = $_POST['telephone'];
$interested = $_POST['interested'];
$message = $_POST['message'];
$submit = $_POST['submit'];


if($submit){

    //prepare email
    $from = 'From: Johnhophotography.com'."\r\n"; 
    $to = 'cloudsblack84@gmail.com'; 
    $subject = "Message from johnhophotography.com";
    $body = "".
        "From: ".$name."\n".
        "E-mail: ".$email."\n".
        "City: ".$city."\n".
        "Telephone: ".$telephone."\n".
        "Interested: ".$interested."\n".
        "Message: ".$message."\n";

    //Send email
    if(mail($to, $subject, $body, $from)){
        echo '<p>Your message has been sent!</p>';
    }
    else{
        die('<p>Something went wrong, go back and try again!</p>'); 
    }
}

?>

暫無
暫無

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

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