简体   繁体   中英

Sending information from html form to email

I have a simple form for a website allowing users to send a query/message to my clients email address.

I'm struggling trying to get this working. So far I have managed to find some code (also via stack overflow) that allows the form to send a blank email to the correct address upon submit. I seem to be missing some code or something that makes the submit button pull information from the form to send.

Below is the code I have.

Thanks (PS I have no experience with PHP, only as to alter the code I previously found to get this far).

<?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>

First you have to remove action="email.php" since you put PHP code in the same file.

Then, you have to remove enctype="text/plain" to get it works.

See this stackoverflow subject

Finally, it is good to test what was send in PHP before doing mail function in addition to your required verification

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM