2015-03-03 113 views
0

我很想啓動我的網站,但首先我需要完成我的聯繫表單,以確保用戶可以與我聯繫。我不是PHP專家或任何接近的專家,所以請理解我的無知。聯繫表格,它是如何工作的?

我準備好並運行了我的服務器。我有一封電子郵件。我有這個網站。我有兩個文件,一個是contact.html,另一個是send.php

contact.html有以下內容:

<!doctype html> 
<html> 
<head> 
    <title>Spotnight - About</title> 
    <link rel="stylesheet" href="style.css"> 
    <link rel="Favicon" href="f.ico" type="image/x-icon"> 
</head> 
<body> 
    <div class="ham_container"> 
    <svg id="hamburger" title="Menu"> 
     <path d="M0,5 30,5" stroke="#eeeeee" stroke-width="5"/> 
     <path d="M0,14 30,14" stroke="#eeeeee" stroke-width="5"/> 
     <path d="M0,23 30,23" stroke="#eeeeee" stroke-width="5"/> 
    </svg> 
    </div> 
    <nav> 
    <ul> 
     <li><a href="http://spotnight.io/">Our Home</a></li> 
     <li><a href="http://spotnight.io/about.html">About Us</a></li> 
     <li><a href="http://spotnight.io/hybon.html">Hybon Sites</a></li> 
     <li><a href="http://spotnight.io/orion.html">Orion Interactives</a></li> 
     <li><a href="http://spotnight.io/studios.html">Spotnight Studios</a></li> 
     <li><a href="http://spotnight.io/shop.html">Spotnight Shop</a></li> 
     <br> 
     <li><a href="http://spotnight.io/contact.html">Contact Us</a></li> 
    </ul> 
    </nav> 
    <main> 
    <h1>Contact us! :)</h1> 
    <h5>Spotnight</h5> 
    <div> 
     <form action="send.php" method="POST"> 
     <input type="text" name="first_name" placeholder="Your first name, eg: 'John'"> 
     <input type="text" name="last_name" placeholder="Your last name, eg: 'Smith'"> 
     <input type="email" name="email" placeholder="Your Email, eg: '[email protected]'"> 
     <select name="subj" size="1"> 
      <option value="new_website">I need a website</option> 
      <option value="new_game">I want a game</option> 
      <option value="new_employee">I want to be part of the team</option> 
      <option value="new_employee_game">I want to participate making games</option> 
      <option value="new_employee_site">I want to participate building sites</option> 
      <option value="new_artist">I'm an artist and need help</option> 
      <option value="something_else">Something else!</option> 
     </select> 
     <textarea name="message" placeholder="Your Message Goes Here!"></textarea> 
     <input type="submit" value="Send!"> 
     </form> 
    </div> 
    </main> 
    <footer> 
    &copy; <span id="year">2015</span> : <a href="http://hybon.spotnight.io/">Spotnight.io</a> : Proudly created by Hybon. 
    </footer> 
</body> 
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script> 
<script src="script.js"></script> 
</html> 

send.php文件有以下內容:

<!doctype html> 
<html> 
<head> 
</head> 
<body> 
    <?php 
    $first_name = $_POST["first_name"]; 
    $last_name = $_POST["last_name"]; 
    $email = $_POST["email"]; 
    $subj = $_POST["subj"]; 
    $message = $_POST["message"]; 
    $formcontent="From: " . $first_name . $last_name . ", " . $email . "\n Subject: " . $subj . "\n Message: " . $message; 
    $recipient = "[email protected]"; 
    $subject = "Contact Form - " . $subj . " - Spotnight.io"; 
    $mailheader = $email . " has tryed to reach you! \r\n"; 

    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
    echo "Thank You! Your message has been recived, we&apos;ll answer as soon as possible!" . $first_name . $last_name . " -" . "<a href="contact.html">Go Back!</a>"; 
    ?> 
</body> 
</html> 

這是所有的文字,這意味着,該代碼是完全一樣的在那裏。我無法理解它,但我仍然不明白它是如何工作的。

所以,如果你是一個超級可怕的php專家,請幫助我理解並修復此代碼,以便稍後處理它,以便其他人瞭解它是如何工作的。

我已經搜索了很多地方,但最簡單的聯繫表格形式並沒有出現在世界檔案中。非常感謝你!

+0

它。看起來像一個簡單的錯誤,在你的$ formcontent行中,你用$ message「」結束它;刪除「,所以它看起來像這樣:$ message; – Epodax 2015-03-03 10:59:48

+0

謝謝,我沒有看到,但即使我已經更新它,它似乎仍然不工作,它只是給我一個空白頁面'send.php' – 2015-03-03 11:02:08

+0

@ julian.a.avar - 這聽起來像你的服務器不支持PHP。 – Quentin 2015-03-03 11:02:50

回答

0
echo "Thank You! Your message has been recived, we&apos;ll answer as soon as possible!" . $first_name . $last_name . " -" . "<a href="contact.html">Go Back!</a>"; 

這裏的問題。 SO的代碼highliter因此而高亮顯示。

用這個代替:

echo /* part of code missing */ $first_name . $last_name . " -" . "<a href='contact.html'>Go Back!</a>"; 
//             mind the ' signs here ^^^^^^^^^^^^^ 

不能包括在其他報價報價沒有逃脫「的,或者使用單引號標誌(我可能已經在術語誤)

+0

等什麼?我很困惑,我會改變什麼? – 2015-03-03 11:10:44

+0

'contact.html''''''''''''''''''''''''''''''''''''''''''' – ForceBru 2015-03-03 11:12:37

+0

謝謝,這有很大的幫助。現在顯示文本,但我一直在等待五分鐘, m使用不是那麼慢,所以它似乎並沒有解決所有的問題... – 2015-03-03 11:17:44

0

您的'send.php'腳本將html與php混合,所以除非您使用輸出緩衝,否則當您嘗試發送電子郵件時,由於html內容已發送至客戶端/瀏覽器,您將遇到錯誤。我會建議send.php腳本是純粹的PHP只。另外,mailheader變量 - 這在我看來是錯誤的 - 我認爲它應該至少包含From:[email protected]字段。從PHP手冊:

$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers); 





    <?php 
    /* send.php */ 
    $first_name = $_POST["first_name"]; 
    $last_name = $_POST["last_name"]; 
    $email = $_POST["email"]; 
    $subj = $_POST["subj"]; 
    $message = $_POST["message"]; 


    $formcontent="From: " . $first_name . $last_name . ", " . $email . "\n Subject: " . $subj . "\n Message: " . $message; 
    $recipient = "[email protected]"; 
    $subject = "Contact Form - " . $subj . " - Spotnight.io"; 
    $mailheader = "From: ".$email . "\r\n"; 

    $res = mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 

    if($res) header('location:/index.php?mailsent=true'); 
    else header('location:/index.php?mailsent=false'); 
    ?> 
+0

所以我只使用''擦除所有的html,還有什麼?因爲我希望電子郵件擁有所有這些信息,所以我不希望它只有以下三件事:主題,消息和標題 – 2015-03-03 11:13:37

+0

上面的例子就是這樣 - 一個例子。您仍然可以包含您在'send.php'腳本中設置的各種變量 - 但不需要html標記 - 一旦發送了郵件,您就可以使用標題將用戶重定向回html頁面。 (header('location:/index.php')等) – RamRaider 2015-03-03 11:17:36

+0

所以我只擦除所有​​的HTML,並堅持''? – 2015-03-03 11:19:26