-1

I was hoping someone could let me know the php code to send the contents of this form through to my email.

Thanks!

I really have absolutely no idea when it comes to php so any help that you could provide would be very much appreciated!

Get in touch to discuss your project!

            <input id="af-showreq" class="af-show-input" type="checkbox" name="showreq" />


            <form class="af-form" id="af-form" novalidate>

                <div class="af-outer">
                    <div class="af-inner">
                        <label for="input-title">Title</label>
                        <input type="text" name="title" id="input-title">
                    </div>
                </div>

                <div class="af-outer af-required">
                    <div class="af-inner">
                        <label for="input-name">Name</label>
                        <input type="text" name="fullname" id="input-name" required>
                    </div>
                </div>

                <div class="af-outer af-required">
                    <div class="af-inner">
                      <label for="input-email">Email address</label>
                      <input type="email" name="email_address" id="input-email" required>
                    </div>
                </div>



                <div class="af-outer af-required">
                    <div class="af-inner">
                      <label for="input-country">Company</label>
                      <input type="email" name="country" id="input-country" required>
                    </div>
                </div>



                <div class="af-outer">
                    <div class="af-inner">
                      <label for="input-phone">Phone Number</label>
                      <input type="email" name="phonenumber" id="input-phone">
                    </div>
                </div>

                <input type="submit" value="Send it over!" /> 

            </form>
        </section>
    </div>
</div>

1 Answers1

1

first of all we want to turn the form into a post request. So when someone hits the submit button it will post the form data to your server. You can do this by changing your form tag to have a action (the page on your site you want to post back to") and method="POST".

<form class="af-form" action="" id="af-form" method="POST">

For more information on that look here.

http://www.w3schools.com/html/html_forms.asp

For post to work you need to make sure all your tags that you want to send over have a name tag. Currently your submit button doesn't change it to:

<input type="submit" name ="submit" value="Send it over!" /> 

Next on the page the post data gets sent to we want to make sure that we have post data. In php all post data is stored in a super variable called POST. So we can check if there is data in here. If there is then we can continue into making the email

if(isset($_POST['submit']){
    //the rest of the code should be done in here
    //as we only want to send the email if we have made a post request
}

Finally we can now take this information to send you an email

we can get input information by doing the following

$example = $_POST['email_address']

example will now have the information that people put in the email_address input box

sending an email in php is done with the mail() function. An example of this can be seen below

mail("whoto@email.com", "I am a subject", "I am the content of the email);

for more information on the mail function look at http://php.net/manual/en/function.mail.php

zidsal
  • 577
  • 1
  • 7
  • 30
  • You may not have your configuration setup to use the mail function. A lot of hosts disable it to stop spam sites. Check your php.ini to see if mail has been disabled. For more information look at: http://stackoverflow.com/questions/8803994/php-mail-not-working-for-some-reason – zidsal Jul 03 '13 at 16:31