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.


form_to_email.php

Source Code
<?
// Check, if submitted.
if($Submit){

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

$to="[email protected]";

$subject="Contact information from website.";

// Get time from server.
$time=date("d/m/Y");

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

// Send email.
mail($to,$subject,$message,$mail_from);
echo "Your contact information has been sent";
}else{

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

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

  • 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.

Advertise
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
PHP Tags
PHP Variables
PHP Control Structures
MySQL
Create Database & Table
Database Connection
Insert Record
Select Record
Update Record
Delete Record

PHPsimple.net
[email protected]