form_sendmail.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="sendmail.php" method="post"> <p>ทดสอบการส่ง e-mail</p> <table width="400" border="0"> <tr> <td>To:</td> <td><input name="MailTo" type="text" /></td> </tr> <tr> <td>Subject:</td> <td><input name="MailSubject" type="text" /></td> </tr> <tr> <td> Message:</td> <td><textarea name="MailMessage" ></textarea></td> </tr> <tr> <td>From:</td> <td><input name="MailFrom" type="text" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> </body> </html>
sendmail.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p><a href="form_sendmail.html">form_sendmail</a></p> <?php $MailTo = $_POST['MailTo'] ; $MailFrom = $_POST['MailFrom'] ; $MailSubject = $_POST['MailSubject'] ; $MailMessage = $_POST['MailMessage'] ; $Headers = "MIME-Version: 1.0\r\n" ; $Headers .= "Content-type: text/html; charset=UTF-8\r\n" ; $Headers .= "From: ".$MailFrom." <".$MailFrom.">\r\n" ; $Headers .= "Reply-to: ".$MailFrom." <".$MailFrom.">\r\n" ; $Headers .= "X-Priority: 3\r\n" ; $Headers .= "X-Mailer: PHP mailer\r\n" ; if(mail($MailTo, $MailSubject , $MailMessage, $Headers, $MailFrom)) { echo "ส่ง e-mail เรียบร้อย" ; //ส่งเรียบร้อย }else{ echo "ไม่สามารถส่ง e-mail ได้" ; //ไม่สามารถส่งเมล์ได้ } ?> </body> </html>
ที่มา: thaicreate.com