2009/09/19

用php的mail函數來發信範例

把下面這一段存成contentme.htm
<html>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<head>
<title>聯絡我們</title>
</head>

<body>

<form method="POST" action="mailer.php">
<p>姓名 <input type="text" name="T1" size="20"></p>
<p><input type="radio" value="V1" checked name="R1">男&nbsp;
<input type="radio" name="R1" value="V2">女</p>
<p>聯絡電話 <input type="text" name="T2" size="20"></p>
<p>電子信箱 <input type="text" name="T3" size="20"></p>
<p>詢問主題 <select size="1" name="D1">
<option>餐廳</option>
<option>宴會</option>
<option>參觀</option>
</select></p>
<p>詢問內容 <textarea rows="5" name="S1" cols="33" class="form"></textarea></p>
<p><input type="submit" value="確定送出" name="B1"><input type="reset" value="重新設定" name="B2"></p>
</form>

</body>

</html>

再把下面這一段存成mailer.php
<?php
$T3 = $_POST['T3'];
$D1 = $_POST['D1'];
$S1 = $_POST['S1'];
$T1 = $_POST['T1'];
$T2 = $_POST['T2'];
$R1 = $_POST['R1'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=Big5\r\n";
$headers .= "To: mailto:yogi@aliok.net/r/n";
$headers .= "From: ".$T1."<".$T3.">\r\n";

$cont = "<html>
<head><title>測試</title></head><body>
<font size=3 color=blue>
姓名: $T1<br>
性別: $R1<br>
聯絡電話:$T2<br>
詢問內容:$S1<br></font>
</body>
</html>";
mail('yogi@aliok.net',$D1,$cont,$headers);
?>
二個相呼應就會把contentme.htm 的表單內容寄到指定的 yogi#aliok.net 的信箱中
只是姓別還沒有做判別式來修正, 只會收到原值
不過還蠻好玩的

竹影掃階塵不動 月穿潭底水無痕
竹月山莊 http://www.aliok.net/