2015-09-05 36 views
-2

所以我爲自己創建了一個網站。由於它有使用計劃,我需要某人幫助:)用於HTML網站的電子郵箱

我需要用戶填寫幾個框,然後發送到我的電子郵件[email protected]

由於我有點新,我現在不知道該怎麼做。

形式:http://imgur.com/U5Q3jrE 這是我的代碼:

 <form action="../index.html" method="post" class="message"> 
      <input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
      <input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
      <input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
      <textarea></textarea> 
      <input type="submit" value="Send"/> 
     </form> 

現在我需要的是,它沒有把我的索引頁,但顯示一個消息,有人喜歡:「您的消息已發送」併發送給我的電子郵件,因爲目前它不會發送給任何東西。

再次我非常新,所以請原諒我的noobness:P

謝謝大家, Waylon194

+4

只是HTML你不能實現這一點。你應該使用服務器端語言如php或java – aimme

+0

你需要這個php: http://php.net/manual/function.mail.php – Arturo

+0

你不能單獨發送客戶端JavaScript的電子郵件,服務器必須支持電子郵件協議才能發送電子郵件 –

回答

0

確定這裏是一個可以用來發送電子郵件的PHP的HTML代碼,您可以下手。

用戶輸入必須始終相應地進行消毒。此代碼僅供演示。

<?php 
//if "email" variable is filled out, send email 
    if (isset($_REQUEST['email'])) { 

    //Email information 
    $admin_email = "[email protected]"; 
    $email = $_REQUEST['email']; 
    $subject = $_REQUEST['subject']; 
    $comment = $_REQUEST['comment']; 

    //send email 
    mail($admin_email, "$subject", $comment, "From:" . $email); 

    //Email response 
    echo "Thank you for contacting us!"; 
    } 

    //if "email" variable is not filled out, display the form 
    else { 
?> 

<form method="post"> 
    Email: <input name="email" type="text" /><br /> 
    Subject: <input name="subject" type="text" /><br /> 
    Message:<br /> 
    <textarea name="comment" rows="15" cols="40"></textarea><br /> 
    <input type="submit" value="Submit" /> 
    </form> 

<?php 
    } 
?> 
+0

你知道多少? – aimme

+0

@ Waylon194 - 編寫一個完整的初學者指南到服務器端編程對於Stackoverflow來說太廣泛了。我建議你找一個介紹性的教程。 – Quentin

+0

你同意@Quentin,但讓他知道服務器端是需要實現這一點。只是給他一個想法,開始知道:) – aimme

-2

您可以結合使用HTML表單標籤的郵寄地址功能的一個小的jQuery功能。

<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
</head> 
<body> 
    <div id="Thankyouoption"> 

    </div> 

<FORM METHOD="post" ACTION="mailto:[email protected]" ENCTYPE="text/plain"> 
       <input type="text" value="Naam" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
       <input type="text" value="E-mail" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
       <input type="text" value="Onderwerp" onFocus="this.select();" onMouseOut="javascript:return false;"/> 
       <textarea></textarea> 
       <input type="submit" id="submitbutton" value="Send"/> 
</form> 

<script type="text/javascript"> 
     $(document).ready(function(){ 
      $('#submitbutton').click(function(){ 
       $('#Thankyouoption').text("Your message has been send"); 
      }); 
     }); 
</script> 
+1

'mailto:'作爲表單動作[太不可靠](http://isolani.co.uk/articles/mailto.html)在WWW上使用。 – Quentin

+1

@ Waylon194 - 這個答案是一個完整的例子(儘管在實踐中完全被破壞的東西不應該被使用)。如果你有什麼不明白的地方,你應該更具體。 – Quentin

+0

我不給這個投票,但它很好的閱讀這個知識 - http://stackoverflow.com/questions/7449767/how-do-i-send-an-html-form-in-an- email-not-just-mailto – aimme