2014-10-31 150 views
-2

我創建了一個HTML表單,沒有任何困難(我對HTML和CSS比較新,但對它們很滿意)。問題是我想要提交按鈕將用戶在表單中輸入的數據發送到我的電子郵件地址。HTML表單使用PHP提交自動電子郵件

我的PHP知識是幾乎不存在,我完全卡住了。如果任何人有耐心幫助,它將是最感謝。

這裏是窗體的代碼...

<!DOCTYPE html> 

<html> 

    <head> 
    <meta charset="utf-8"> 
    <title>Life Academy | Pre-course questionnaire</title> 
    <link rel="stylesheet" href="css/normalize.css"> 
    <link rel="stylesheet" href="pcq.css"> 
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700,800' rel='stylesheet' type='text/css'>  
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    </head> 

    <body> 
    <div id="formbg"> 
    <div id="formcontent"> 
     <img src="pcqlogo.png" class="logo"> 
     <p><strong>Retirement Planning Course<br>Anonymous Pre-course Questionnaire</strong><br>So that the course may more accurately reflect your interests and possible concerns, we would like you to complete and return this questionnaire before the start of the course, by email, to<br> <a href="mailto:[email protected]"><strong>[email protected]</strong>.</a></p> 
     <form> 
      Age<br> <input type="text" name="age"><br> 
      Years with present/last company<br> <input type="text" name="yearswithcompany"><br> 
      Leaving Date<br> <input type="text" name="leavingdate"><br> 
      Job Role<br> <input type="text" name="role"><br> 

      Do you have a company or occupational pension plan?<br> 
      <input id="yes" type="radio" name="companypension" value="yes"> 
      <label for="yes">Yes</label> 
      <input id="no" type="radio" name="companypension" value="no"> 
      <label for="no">No</label><br> 

      Do you have a personal &#40private&#41 pension plan?<br> 
      <input id="yes" type="radio" name="personalpension" value="yes"> 
      <label for="yes">Yes</label> 
      <input id="no" type="radio" name="personalpension" value="no"> 
      <label for="no">No</label><br> 

      What would you like to gain from this course? Please describe in detail.<br> <textarea name="liketogain" class="largetextbox"></textarea><br> 
      What are your main activities outside of work?<br> <input type="text" name="activities"><br> 
      How do you think these activities will develop/change in the near future?<br> <textarea name="activitiesdevelop" class="largetextbox"></textarea><br> 
      Have you any concerns about the future? If so, list them here:<br> <textarea name="futureconcerns" class="largetextbox"></textarea><br> 
      Do you want to make changes to your health/lifestyle? If so, please describe the changes.<br> <textarea name="healthlifestylechanges" class="largetextbox"></textarea><br> 
      How would you like the emphasis of your life to change in the future with respect to work/voluntary activity?<br> <textarea name="work" class="largetextbox"></textarea><br> 
      Do you have any dietary requirements?<br> <input type="text" name="diet"><br> 
      Do you have any other special requirements?<br> <textarea name="special" class="largetextbox"></textarea><br> 
      <input type="submit" value"submit"> 
     </form> 
    </div> 
    </div> 
    </body> 

</html> 
+0

......換句話說,你正在尋找一個PHP處理程序來發送郵件,對嗎? – 2014-10-31 20:36:18

回答

0

讓自己PHP提交頁面,並設置您的形式張貼到它:

<form action="file_name.php" method="POST"> 
//form fields go here 
</form> 

然後你需要一個PHP郵件類。我建議PHPMailer。
基本用法和下載:https://github.com/PHPMailer/PHPMailer

像這樣的文件:
PHP_mailer.php

<?php 
include 'mailer'; 
include 'library'; 
include 'files'; 
....rest of mailer code goes here.... 
?> 

在PHP郵件頁面,您可以用$_POST['name of field goes here']訪問任何一組字段。所以前例。 $_POST['name']$_POST['age']

請注意,這是一個非常基本的解釋,需要額外的步驟,比如表單驗證,很可能使用Javascript,並且它需要您設置一些關於如何使用電子郵件格式的設置等。最佳選擇是嘗試並自己測試一下,直到你可以開始工作。如果難以理解,還有大量的PHP文檔可用。