我正在尝试将 php 添加到我的联系我们页面,以确保消息至少有几个字符长才能发送。我试过 if (strlen()> 2) 但它只是让消息通过。enter code here
<div id="phillya11">
<a href="#" style="text-decoration:none;color:#FFF5ee">
Contact us
</a>
</div>
<div id="soon4">
<form action="index.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p>
<textarea style="width:475px; height:175px;margin-left:7%" name="message"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
</div>
PHP:
<?php
if (strlen($message)> 2)
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "myemail";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
jQuery:
$("#phillya11").click(function ()
{
$("#soon4").show();
$("#soon").hide();
$("#soon1").hide();
$("#soon2").hide();
$("#soon3").hide();
$('#close4').click(function ()
{
$("#soon4").hide();
});