Article Index

สร้างไฟล์ส่งข้อมูลเข้าอีเมล์
1. สร้างไฟล์ชื่อ send.php
2. ดับเบิ้ลคลิกเปิดไฟล์
3. คลิก Code

 

4. พิมพ์คำสั่ง PHP ลงไปตามตัวอย่าง
<?php
if(isset($_POST['send'])) setcookie("Mail",1, time()+30);
else die("No form submitted");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-874">
<title>Sending Mail</title>
</head>

<body>
<?php
if(isset($_COOKIE['Mail'])) die("You can't send another email within 30 seconds");
//validating email address
if(!ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$",$_POST['mailto'])) die("Recipient email address is not correct");
if(!ereg("^[^@ ]+@[^@ ]+\.[^@ \.]+$",$_POST['mailfrom'])) die("Sender email address is not correct");

//setting up headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: ".$_POST['mailto']."\r\n";
$headers .= "From: ".$_POST['mailfrom']."\r\n";

// now sending mail
if(mail($_POST['mailto'], $_POST['mailsubject'], nl2br($_POST['mailmsg']), $headers)){
echo "Mail sent to <b>".$_POST['mailto']."</b> sucessfully";
} else{ die("Mail sending error"); }
?>

</body>

</html>
5. เสร็จแล้วบันทึกงานเก็บไว้