Contact Us

Scripts: PHP :: PHP mail functions >> Library Article #11

Developer's Section

PHP Basic Send Mail Function & Form
By: Karthik

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (2544)

Learn a simple way to send an email using PHP and a simple html form.

This is a very simple tutorial, yet works like a charm and does all the things it needs to do. First of all, here's the code:

 Code Snippet 1

$subject = $_POST['subject']; // This is will be the subject of the email
$email = $_POST['email'];
$comments = $_POST['comments'];
$submit = $_POST['submit'];

// Replace with your email address!
mail("", "$subject", "$email", "$comments");

Save it as contact.php

Lets break it down. The variables gather the information from the forms and make it a cleaner code. The if($submit) tells the mail(); function that it can send the email. It helps to keep it from sending annonymous emails to your email address. You have to change the to your email address to be able to get the email from the user. The rest is fine do not change, unless you need to.

Now for the forms!

 Code Snippet 2

<form method="post" action="contact.php">
 Subject:<br />
<input type="text" name="subject" size="20">
<br /> 
<br />
<input type="text" name="email" size="20">
<br />
<br />
<textarea cols="20" rows="5" name="comment"></textarea>
<br />
<input type="submit" value=" Submit ">

This is really simple, I should not have to explain it. Leave the name fields alone, unless you need to. You can change the size too.

Script Info: User Submitted Script.
Author: Karthik.
Home Town: Trichy, India.

See other Scripts in PHP mail functions

Submit Your Scripts:

If you would like to have your PHP scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]