【发布时间】:2010-12-16 16:28:36
【问题描述】:
我正在尝试在 PHP 中创建一个非常简单的邮件表单,但出现错误:
PHP公告:未定义索引:在/var/www/html/sites/send_contact.php第10行,referer:http://example.com/contact2.php
我的 PHP 文件如下所示:
<?php // send_contact.php
// Contact subject
$subject =$_POST["$subject"];
// Details
$message=$_POST["$detail"];
// Mail of sender
$mail_from=$_POST["$customer_mail"];
// From
$name2=$_POST["$name2"];
$header="From: $mail_from\r\n";
// Enter your email address
$to="joe@mail.com";
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
【问题讨论】:
-
如果您的字段被命名为主题,那么您将输入 $_POST["subject"] 。如果您希望 $_POST 中的值具有存储在 $subject 中的键,请使用 $_POST[$subject] 。
-
以防万一:一旦这个问题解决了,一定要在投入生产之前做一些输入清理...phpbuilder.com/columns/ian_gilfillan20060412.php3