Click here to Skip to main content
15,891,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Im trying to do a form where the client enters his details.


Then if its correct, details are sent to my email and if incorrect, it sends out an error.


I did the table and I have a PHP file but I dont know how to connect them together I have been trying for almost 2 days.

Please help

What I have tried:

HTML
<pre lang="<FORM> 

<center>    <table width="1000px">
                    </tr>
                    <tr>
                        <td>
                <label for="name"> Name and Surname </label>
                        </td>     
                <td>
                <input type="text" name="name" maxlength="50" size"30">
                </td>
                    </tr>
                 
                    
                <td>
                        <label for="email"> Email Address </label>
                    </td>
            <td>
                    <input type="text" name="email" maxlength="70" size "40">
                </td>
            </tr>
            
            
            <td>
                <label for="phone"> Phone Number </label>
            </td>
                <td>
                    <input type="text" name="phone" maxlength="80" size "30">
                </td>
            </tr>
            
            
            <td>
            <label for="message"> Message </label>
            </td>
            <td>
            <textarea type="text" name="msg" maxlength="1000" cols ="25" rows="6"></textarea>
            </td>
        </tr>


        <tr>
            <td colspan="2" style="text-align:center">
                <input type="submit" value = "submit">
            <td>
            </tr>

	         <?php
// Check for empty fields
if(empty($_POST['name'])  		||
   empty($_POST['email']) 		    ||
   empty($_POST['phone']) 		||
   empty($_POST['message'])	||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
	echo "No arguments Provided!";
	return false;
   }
	
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
	
$to = 'marcurmi94@gmail.com'; 
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: yourname@yourdomain\n"; 
$headers .= "Reply-To: $email_address";	
mail($to,$email_subject,$email_body,$headers);
return true;			
?>
	 
    </table>
</form>
">
Posted
Updated 22-Aug-19 12:30pm
Comments
enhzflep 1-Dec-18 17:13pm    
What you need, is not a table (though, you may choose to use one for layout purposes - against almost all advice).

You need a form, whose `action` points to the PHP file you'd like to catch all the details with.

Here, like this: https://www.w3schools.com/php/php_forms.asp
Member 14552976 23-Aug-19 3:15am    
you just need form and named its as "post" get the data from

1 solution

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
First name: <input type="text" name="FirstName" value="Mickey"><br>
Last name: <input type="text" name="LastName" value="Mouse"><br>
<input type="submit" value="Submit">
</form>

<p>Click the "Submit" button and the form-data will be sent to a page on the server called "/action_page.php".</p>

</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900