0

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>
Alex E
  • 107
  • 10

1 Answers1

1

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

Community
  • 1
  • 1
Vincent G
  • 8,547
  • 1
  • 18
  • 36
  • Thanks, this worked but only so far. It is now posting the users name in the email subject (correct), then gives the phone number and email address fields. For some reason it's missing out anything from the 'message' text area. – Alex E Mar 16 '16 at 12:26
  • Check how the mail() function if formatted : http://php.net/manual/fr/function.mail.php The content of the message should be on the third parameter – Vincent G Mar 16 '16 at 12:29