How To Make A Contact Form For Your Website

1 post Page 1 of 1
Contributors
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

hello guys hehaho;

i am now going to tell you how to create a contact form using php and html and i want to say that some of you may know how to create in other way some of you may not know how to create this so thats why i want to write .

i am using the same contact form on my website by the way i dont think it is advanced but its ok cooll;

first you need to create the php file so open your favorite text editor and add these php codes inside
Code: Select all
<?php

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject']; 
$msg = $_POST['message']; 


$from = 'From: ' . $email; 

$message = <<<EOD

Hey Shim, Looks Like You Have a Contact <br />
<hr />
<br />

Name: $name
Email: $email
Subject of Inquiry: $subject

<br />

Message: <br />
$msg
<br />
<hr />

EOD;

mail('admin@example.com', $subject, $message, $from) or die("There was an error!"); 

echo 'Thanks for Contacting Us, We Will Get Back to Your Shortly!';

?>
now this is
Code: Select all
$name = $_POST['name'];
the name field and this is
Code: Select all
$email = $_POST['email'];
the email field and this is
Code: Select all
$subject = $_POST['subject'];
the subject field and this is the message field :ugeek:
Code: Select all
$msg = $_POST['message'];

this declares the $form variable and assign it the value of 'from: ' and the email
Code: Select all
$from = 'From: ' . $email;

this EOD helps us to use formatted HTML In PHP
Code: Select all
$message = <<<EOD

Hey Shim, Looks Like You Have a Contact <br />
<hr />
<br />

Name: $name
Email: $email
Subject of Inquiry: $subject

<br />

Message: <br />
$msg
<br />
<hr />

EOD;
this constructors the function mail()
Code: Select all
mail('Your Email Here', $subject, $message, $from) or die("There was an error!");

replace admin@example.com with your email address
replace shim with your name

this echo a server response
Code: Select all
echo 'Thanks for Contacting Us, We Will Get Back to Your Shortly!';
now save the file as send.php and now if you want to put the form in your contact form of your website open the html file in your notepad and find a place to have the contact form visible and add this codes
Code: Select all

	<form action="send.php" method="post">
	
    <input id="sender" type="text" placeholder="Name" name="name" /><br /><br />

    <input id="email" type="text" placeholder="Email" name="email" /><br /><br />
	
    <input id="subject" type="text" placeholder="Subject" name="subject" /><br /><br />

    <textarea id="contact-content" placeholder="Your enquiries" name="message"></textarea><br /><br />
   
    <input id="consubmit" type="submit" name="consubmit" value="Send" /><br /><br />
	
	</form>
	
the form action ="send.php" and the method "post" means the forms uses send.php for action and post :geek:

now save your html page and to test it you need to upload the files to your host ;)

thanks for reading and i hope this is helpful and again sorry for my bad english if anything bad or else 'do nothing :lol:
Find my programs on Softpedia
1 post Page 1 of 1
Return to “Help & Support”