---
title: phpMailForm (tc)
description: 用 HTML form 加 PHP mail() 做申請表，submit 去 mail_handler.php 寄出郵件。
url: "https://aaronchan.com/zh/kb/php-mail-form/"
updated: "2026-09-15"
category: "Code-php+MySQL (tc)"
---

# phpMailForm (tc)

用 HTML form 加 PHP mail() 做申請表——form 填完 submit 去 mail_handler.php，用 mail() 寄出 subject 同 message。寄到就顯示 Your application was sent!，失敗就顯示 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!
```
