PHP Mail Form
通过 PHP,您能够在自己的站点制作一个反馈表单。下面的例子向指定的 e-mail 地址发送了一条文本消息:
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "someone@example.com", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
else
//if "email" is not filled out, display the form
{
echo "
Email:
Subject:
Message:
";}
?>
例子解释:
首先,检查是否填写了邮件输入框
如果未填写(比如在页面被首次访问时),输出 HTML 表单
如果已填写(在表单被填写后),从表单发送邮件
当点击提交按钮后,重新载入页面,显示邮件发送成功的消息