PHP simple : PHP tutorial, MySQL tutorial
PHP Tutorial - Free PHP Script

Home | Tutorials | Php vs Node.Js | Web Tools

Form to Email

Tutorials > Form to Email

You can apply this tutorial for your contact form on your sites. This tutorial shows you in 1 file with a normal contact information form. When you submit, this file will be sent an email immediately to the target email including in codes.


Source Code
// Check, if submitted.

Send email to "webmaster@localhost".
If you want to send more than 1, use "," between the second, third,...
Ex. webmaster@localhost, [email protected], [email protected], ...


$subject="Contact information from website.";

// Get time from server.

$mail_from="From:$email n";
$mail_from .="Content-Type: text/html; charset=utf-8 n";
Contact on : $time<br>
Name : $name<br>
Email : $email<br>
Comment : $comment

// Send email.
echo "Your contact information has been sent";

// Do following codes if not found "Submit" value.(Not submitted)

<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form action="<? echo $PHP_SELF; ?>" method="post" name="form" id="form">
<td align="right">Your name : </td>
<td><input name="name" type="text" id="name" /></td>
<td align="right">Your Email : </td>
<td><input name="email" type="text" id="email" /></td>
<td align="right" valign="top">Comment/ Request : </td>
<td><textarea name="comment" cols="60" rows="5" id="comment"></textarea></td>
<input type="submit" name="Submit" value="Submit Form" />
<? } ?>

  • Copy this code and save as form_to_email.php to your root folder, open this file by browse to http://localhost/form_to_email.php.
  • Fill in all text fields and click "Submit" button.
  • Open your email client program to recieve email.

Put Ebay RSS Feeds onto your website
SEO Elite Software
Domain Dashboard CPanel & Seo Manager
Work at Home Ideas and Opportunities
Introduction & Get Start
Using Form
PHP Tags
PHP Variables
PHP Control Structures
Create Database & Table
Database Connection
Insert Record
Select Record
Update Record
Delete Record
[email protected]