ใครๆ ก็คงอยากทำหน้า Form Contact แล้วส่งเมล์กันเนอะ
จะสอนวิธีทำแบบง่ายๆ เด็กประถมก็ทำได้ ตามมาเลย

Code แบบฟอร์ม

<form action='sendmail.php' method='post'>
หัวข้อ :  <input type='text' name='subj' /><br />
ชื่อ : <input type='text' name='name' /><br />
Email : <input type='text' name='email' /><br />
Tel.  : <input type='text' name='tel' /><br />
ข้อความ : <textarea name="msg" rows="4" cols="30"></textarea><br />
<input name="submit" type='submit' value='   ส่ง   ' />
</form>

Code sendmail.php (ใช้ชื่ออื่นก็ได้นะ!!!)

if (!isset($_REQUEST["mto"])){
$subj = $_POST['subj'];
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$msg = $_POST['msg'];
} else {
$subj = $_REQUEST["subj"];
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$tel = $_REQUEST["tel"];
$msg = $_REQUEST["msg"];
}
$msgs .= " จากคุณ  ".$_POST['name'].'<br>';
$msgs .= " โทร  ".$_POST['tel'].'<br>';
$msgs .= "ข้อความ ".$_POST['msg'];
$txtfrom = "From: ".$email."\nX-Mailer: PHP/" . phpversion();
if(mail("to@email.com", $subj, $msgs, $txtfrom )) {
echo 'ดำเนินการส่งอีเมล์เรียบร้อย';
} else {
echo 'ไม่สามารถติดต่อ Server ได้';
}
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • Add to favorites
  • email
  • RSS
  • Share/Bookmark