【发布时间】:2014-01-08 22:17:45
【问题描述】:
我在我的网站上有一个简单的订阅时事通讯表格。我希望你能帮助我使它更加用户友好。 我的表格不能做什么: - 它不能回显“成功”“不成功”不离开页面(它在新页面中显示状态,这令人沮丧) - 它无法验证正确和错误的电子邮件(如果你放了一些垃圾,我还是会收到)
这些是我的表单的主要问题。请您指导我一些有用的tuts,或者只是更正我的代码。任何帮助将不胜感激!
HTML:
<div class="subscribe">
<form method="POST" action="subscribe.php">
<p><input type="text" name="Name" size="24" maxlength="40" style="font-family:'Times New Roman', Times, serif" value="Ваше имя" onfocus="if (this.value == 'Ваше имя') {this.value = '';}" onblur="if (this.value == '') {this.value ='Ваше имя';}"></p>
<p><input type="text" name="Email" size="24" maxlength="40" style="font-family:'Times New Roman', Times, serif" value="Ваш email" onfocus="if (this.value == 'Ваш email') {this.value = '';}" onblur="if (this.value == '') {this.value ='Ваш email';}"></p>
<p><input type="image" value="submit" name="Submit" src="images/subscribe.png"></p>
</form>
</div>
PHP:
<?php
$recipient = "order@dastiche.kz";
$subject = "Subscriber";
$name = $_POST['Name'];
$email = $_POST['Email'];
$location = "index.html";
$sender = $recipient;
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
if (($name != "") or ($email != ""))
// Если существуют проверяем...
{
if ((strlen($name) >= 2) and (strlen($name) <= 25))
{
$name = stripslashes($name);
$name = html_entity_decode($name);
$name = strip_tags($name);
}
else
{
echo " something is wrong with name field ";
echo "<center><input name='back' type='button' value='get back'
onclick= 'javascript:history.back()'></center>";
}
if (eregi("^[._a-zA-Z0-9-]+@[.a-zA-Z0-9-]+.[a-z]{2,6}$", $email))
{
$email = stripslashes($email);
$email = htmlspecialchars($email);
$email = strip_tags($email);
}
else
{
echo "There are some mistakes in the \"E-mail\" field";
echo "<center><input name='back' type='button' value='try again'
onclick= 'javascript:history.back()'></center>";
}
}
// Если не существуют выводим сообщение...
else
{
echo "Please, fill in blanks";
echo "<center><input name='back' type='button' value='try again'
onclick= 'javascript:history.back()'></center>";
}
if (($name) and ($email))
{
echo "thanks for subscription!";
}
mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");
header( "Location: $location" );
?>
【问题讨论】:
标签: php email subscription