Send email using the answer from a form

the mail() function

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jan 17, 2017 10:51 am

Tue Jan 17, 2017 10:56 am

I have a problem with creating the PhP script for my contact-form. My html-form looks like this:

Code: Select all

    <div id="getintouch" class="contact_area fix">
        <div class="wrapper contact_us fix">
            <h4>LET’S <span class="header_bold">WORK TOGETHER</span></h4>
            <p>A very long text wold go here</p>
            <span>LEAVE YOUR DETAILS AND WE’LL GET IN TOUCH</span>
            <form id="form" class="bottom_form fix" action="action.php">
                <span class="input_icon"><i class="fa fa-user"></i></span>
                <input name="name" type="text" placeholder="Your name">
                <span class="input_icon_two"><i class="fa fa-envelope"></i></span>
                <input name="email" type="email" placeholder="Your preferred email address">
                <button id="formsubmit">Submit</button>
I am wondering what I should write in my action.php file to make the server send a mail (to me) with the name and email address that was registred in the form.

php-forum Fan User
php-forum Fan User
Posts: 622
Joined: Sat Jun 06, 2015 11:46 am

Tue Jan 17, 2017 11:22 am

Normally you would have a method value on your form tag so you can POST the data back to the server:

Code: Select all

<form id="form" class="bottom_form fix" action="action.php" method="POST">
Then you will be able to access the values entered into the form with PHP code like this:

Code: Select all

$_POST['name'] and $_POST['email']
You should of course sanitize any inputs received from users POSTed to the server.

There are different options for sending an email, this is probably the simplest:

Post Reply