---
title: phpMailForm (en)
description: An application form with an HTML form and PHP mail(); posts to mail_handler.php to send the email.
url: "https://aaronchan.com/kb/php-mail-form/"
updated: "2026-09-15"
category: "Code-php+MySQL (en)"
---

# phpMailForm (en)

An application form built from an HTML form plus PHP's mail() — the form posts to mail_handler.php, which sends the subject and message with mail(). On success it prints "Your application was sent!", on failure "mail can't be delivered".

## mail.php

 Copy

```
<form name="form1" method="post" action="mail_handler.php">
  <table width="620" border="0" cellspacing="0" cellpadding="5" class="txt1">
    <tr>
      <td width="100">Your Name:</td>
      <td width="500"><input name="name" type="text" id="name" style="width:500" size="70"></td>
    </tr>
    <tr>
      <td>Your E-mail:</td>
      <td><input name="email" type="text" id="email2" style="width:500" size="70"></td>
    </tr>
    <tr>
      <td>E-mail subject:</td>
      <td><input name="subject" type="text" id="subject2"  style="width:500" value="Re: Applicaton for <?=$_GET["post"]?>" size="70"></td>
    </tr>
    <tr>
      <td valign="top">Message:</td>
      <td><textarea name="message" cols="70" rows="20" id="textarea2" style="width:500"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Send Application">  </td>
    </tr>
  </table>
</form>
```

## mail_handler.php

 Copy

```
if(!mail("info@jobexpresshk.com", stripslashes($subject), stripslashes($message), stripslashes($headers)))
{
		echo "mail can't be delivered to ";
    echo "<br><a href='javascript:history.back()'>[ BACK ]</a>";
}
else
{
    echo "Your application was sent! <br>";
    echo "<br><a href='javascript:window.close()'>[ CLOSE ]</a>";
}

?>
```

**output:**

```
Your application was sent!
```
