为什么这个PHP电子邮件表单不在发送时添加消息?


Why doesn't this PHP email form add the message when sending?

我的网站上有一个简单的联系表单。提交成功,并将邮件发送到我的邮箱。但有一个问题:无论你在消息部分输入什么都不会被发送;当我收到电子邮件时,它返回空白。

我怎么也弄不明白这是为什么。

这是我让它运行的网站:http://javinladish.com/contact

下面是我在HTML页面上用于消息输入的代码:

<div contenteditable="true" class="validate[required,length[6,300]] message" id="message" placeholder="Start writing your message here..."></div>

这是点击send时提交的PHP:

/* Set e-mail recipient */
$myemail = "javinladish@gmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name']);
$email = check_input($_POST['email']);
$message = check_input($_POST['message']);
$subject = "Email from javinladish.com";
/* If e-mail is not valid show error message */
if (!preg_match("/(['w'-]+'@['w'-]+'.['w'-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);

是因为我使用可满足的div而不是常规的表单元素吗?这和PHP有关吗?

提前感谢所有帮助我的人。

您的消息框是使用contenteditable DIV构建的,但不会与POST数据一起提交。您需要使用<TEXTAREA>,或者使用一些javascript来提取消息并将其添加到POST

下面是所需Javascript的基本示例。这是不是生产就绪代码。

<!doctype html>
<html>
<body>
<div id=messageDiv contenteditable=true>Here's some content</div>
<form onSubmit="sendData();">
<input type=text name=email>
<input type=hidden name=message id=formMessage>
<input type=submit name=submit value='Submit'>
</form>
<script>
// event handler function called when the form is submitted.
// Find the editable DIV, extract the contents. Find a hidden
// field in the form and place the contents in it.
// return true to let the form submit take place.
function sendData() {
    var message = document.getElementById('messageDiv').innerHTML;
    document.getElementById('formMessage').value = message;
    return true;
}
</script>
</body>
</html>