簡體   English   中英

從html表單發送信息到電子郵件

[英]Sending information from html form to email

我有一個簡單的網站表格,允許用戶向我的客戶的電子郵件地址發送查詢/消息。

我正在努力使此工作正常。 到目前為止,我設法找到了一些代碼(也通過堆棧溢出),這些代碼允許表單在提交后將空白電子郵件發送到正確的地址。 我似乎缺少一些代碼或使“提交”按鈕從表單中提取信息以進行發送的東西。

下面是我的代碼。

謝謝(PS我沒有PHP經驗,只是為了改變我之前發現的實現此目的的代碼)。

<?php
    mail('chameleonyeadon@gmail.com', $_POST['name'], $_POST['email'], $_POST['number'], $_POST['message']);
?>  

<form method="post" action="email.php" enctype="text/plain">
                    <!-- name-->
                    <label class="contact__form--label"><em>What is your name?</em><br> 
                        <input type="text" name="name" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your name here" maxlength="30" required="required"/></label><br>
                    <!-- email-->
                    <label class="contact__form--label"><em>Do you have an email address?</em><br>
                        <input type="email" name="email" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter your email address here" maxlength="50" required="required"/></label><br>
                    <!-- number-->
                    <label class="contact__form--label"><em>Can we contact you by phone?</em><br>
                        <input type="number" name="number" class="contact__form__inputbox contact__form__inputbox--marg contact__form__inputbox--pad" placeholder="Enter a phone number we can use here" maxlength="50" required="required"/></label><br>
                    <!-- message--> 
                    <label class="contact__form--label"><em>What is your message?</em><br>
                        <textarea name="message" required="required" class="contact__form__inputbox contact__form__inputbox--marg contact__form__textarea contact__form__inputbox--pad" placeholder="Enter your message here"></textarea></label><br>   
                    <div class="contact__form__btns">
                        <input type="submit" value="Send" class="btn btn--brdr btn--padding--less">
                        <input type="reset" value="Clear" class="btn btn--brdr btn--padding--less btn__formpos">    
                    </div>      
                    </form>

首先,您必須刪除action="email.php"因為您將PHP代碼放入了同一文件中。

然后,您必須刪除enctype="text/plain"才能使其正常工作。

請參閱此stackoverflow主題

最后,除了required驗證外,最好在執行郵件功能之前測試PHP發送的內容

暫無
暫無

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

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