How to Insert an Email Submit Form in MySQL & PHP
You can create an email form using both PHP and MySQL. The form can be used to submit information from your website to you via email. You can use both coded and non-coded options to create an email form. If you are unfamiliar with PHP and MySQL, or if your Web host does not support direct access to a MySQL database, use a no-coding option that remotely generates the PHP and MySQL files needed to create a submission form on your website.
Instructions
-
Create the Database
-
1
Open your browser and navigate to your website's MySQL interface to create the database for your PHP form.
-
2
Run the following script to create the database for your contact form:
CREATE TABLE IF NOT EXISTS 'contact' (
'id' int(11) NOT NULL auto_increment,
'name' varchar(100) NOT NULL,
'email' varchar(100) NOT NULL,
'comment' text,
'date' datetime NOT NULL,
'ip' varchar(255),
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -
-
3
Open a text file on your computer to create the form, then copy and paste the following text into the file:
<form id="contact" name="contact" action="contact.php" method="post">
<p><label>Name: <input type="text" id="name" name="name" value="" /></label></p>
<p><label>Email: <input type="text" id="email" name="email" value="" /></label></p>
<p><label>Comments:<br /><textarea id="comment" name="comment"></textarea></label></p><input type="hidden" id="action" name="action" value="submitform" />
<p><input type="submit" id="submit" name="submit" value="Submit" /> <input type="reset" id="reset" name="reset" value="Reset" /></p>
</form>
Create the Database Connection
-
4
Open the file you want to use to insert the code for the form, using your favorite text or HTML editor.
-
5
Insert the code in the file where you want your form to appear on your website. You can use the form below as a template if you need to make changes to the form:
<form method="post" action="contact.php"> Email: <input name="email" type="text"><br> Message:<br> <textarea name="message" rows="20" cols="45"></textarea><br> <input type="submit"> </form>
-
6
Open your favorite text editor to create the PHP file used for your form.
-
7
Use the following code to create your PHP file:
<?php $to = "you@yoursite.com"; $subject = "Contact Us"; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; $headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?>
-
8
Save the PHP file as "contact.php."
No-Coding PHP and MySQL Form
-
9
Open your favorite browser and visit the PHP FormMail Generator website at phpfmg.sourceforge.net.
-
10
Click on the "Get My Form" link.
-
11
Enter your email address and the subject for the email you will receive each time the form is submitted.
-
12
Enter each field label, field type and user instructions in each corresponding text box. Click on the "Create & Download Form" button.
-
13
Save the address for the the admin panel, login email and password. You will need this information to access and download form data information and make changes to your form.
-
14
Click on the "Download Form" link. The file is download automatically to your default downloads folder.
-
15
Open your downloads folder and double-click the "myform.zip" file.
-
16
Extract all of the files in the archive to your desktop.
-
17
Open your favorite FTP program and upload all of the files from the archive to the same folder on your server.
-
18
Direct users to access the form from YourWebsite.com/folder_name/form.php.
-
1