Easy HTML Form Emailer Written in PHP

February 13th, 2010

PHP Script

This easy to use script makes it easy to have an HTML form send its contents to you via email.  The PHP script is just a few lines of code.  Just customize four lines of code so that the script will send the email to the right address.  The lines of code in the easymailer.php file to modify are:

define("EMAIL","enteremail@here.com",false);
define("DESTINATION","success.htm", false);
define("SUBJECT","An email from your website.",false);
define("FROM","webmaster@yousite.com",false);

The first line configures who will receive the emailed form.  The second line determines what page the visitor will be sent to after the script has emailed you.  The third line is the determines what you will see in the subject line of the email you receive.  Line four determines who the sender will be in the email you receive.

The HTML Form

The only requires to use the PHP script is to set the form’s method attribute to post and the action attribute to ‘easymailer.php’.  See the example form below:

<form action="easymailer.php" method="post">
<input name="name" type="text" />
<input name="email" type="text" />
<input name="action" type="submit" value="Submit" />
</form>

When the visitor clicks submit the form data will be redirected to the easymailer.php script which will send the email and then redirect them to the page you configured it to.

You can download an example below just remember to change the four lines  in the easymailer.php file so it is properly customized for your needs. Then, upload easymail.php to your PHP enabled web server.

Download easy mailer script