联系人表单/php区分大小写
我正在使用这种联系方式,它似乎工作良好,只有一个例外! 电子邮件地址的输入字段区分大小写。 因此,如果你使用的是像iPad这样的设备,它会自动大写电子邮件地址的第一个字母(Name@gmail.com) 表单将无法识别它是有效的电子邮件地址。 有解决办法吗联系人表单/php区分大小写,php,html,forms,email,post,Php,Html,Forms,Email,Post,我正在使用这种联系方式,它似乎工作良好,只有一个例外! 电子邮件地址的输入字段区分大小写。 因此,如果你使用的是像iPad这样的设备,它会自动大写电子邮件地址的第一个字母(Name@gmail.com) 表单将无法识别它是有效的电子邮件地址。 有解决办法吗 <title>My basic contact form</title> <link href="css/bootstrap.min.css" rel="stylesheet"> </
<title>My basic contact form</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Contact Me</h1>
</div>
<?php
// check for a successful form post
if (isset($_GET['s'])) echo "<div class=\"alert alert-success\">".$_GET['s']."</div>";
// check for a form error
elseif (isset($_GET['e'])) echo "<div class=\"alert alert-error\">".$_GET['e']."</div>";
?>
<form method="POST" action="contact-form-submission.php" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="input1">Name</label>
<div class="controls">
<input type="text" name="contact_name" id="input1" placeholder="Your name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="input2">Email Address</label>
<div class="controls">
<input type="text" name="contact_email" id="input2" placeholder="Your email address">
</div>
</div>
<div class="control-group">
<label class="control-label" for="input3">Message</label>
<div class="controls">
<textarea name="contact_message" id="input3" rows="8" class="span5" placeholder="The message you want to send to me."></textarea>
</div>
</div>
<div class="form-actions">
<input type="hidden" name="save" value="contact">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</form>
</div>
</body>
</html>
//contact-form-submission.php
<?php
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {
header("Location: contact-form.php"); exit;
}
// get the posted data
$name = $_POST["contact_name"];
$email_address = $_POST["contact_email"];
$message = $_POST["contact_message"];
// check that a name was entered
if (empty ($name))
$error = "You must enter your name.";
// check that an email address was entered
elseif (empty ($email_address))
$error = "You must enter your email address.";
// check for a valid email address
elseif (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email_address))
$error = "You must enter a valid email address.";
// check that a message was entered
elseif (empty ($message))
$error = "You must enter a message.";
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
header("Location: contact-form.php?e=".urlencode($error)); exit;
}
// write the email content
$email_content = "Name: $name\n";
$email_content .= "Email Address: $email_address\n";
$email_content .= "Message:\n\n$message";
// send the email
mail ("somename@gmail.com", "New Contact Message", $email_content);
// send the user back to the form
header("Location: contact-form.php?s=".urlencode("Thank you for your message.")); exit;
?>
我的基本联系方式
联系我
名称
电子邮件地址
消息
发送
//contact-form-submission.php
到
特别是,你想在赛前比赛中打出“我”的旗子。有关更多信息,请参阅此答案
顺便说一句,这真是一个丑陋的规则。。英雄联盟这是我用的
/^[^@]+@[-\w._]+\.[a-zA-Z]+$/
演示
正如我在评论中所说,您可以使用当前的方法进行此操作
改变
$email_address = $_POST["contact_email"];
到
它会将输入的所有内容转换为小写
但是,我建议您使用验证电子邮件
例如:
$email_address = strtolower($_POST["contact_email"]);
if(!filter_var($email_address, FILTER_VALIDATE_EMAIL))
{
echo "E-mail is not valid"; exit;
}
“有解决方法吗?”-是的,假设您需要所有小写字母的电子邮件地址。@Fred-错误,请尝试用于检查电子邮件地址的regx中的'i'标志email@ArtisiticPhoenix50%错了当然……好吧,但不是完全错了,至少我不这么认为。然而,就我的一生而言,我看不出电子邮件是如何区分大小写的;这根本没有任何意义。如果有的话,标准的PHP电子邮件验证is-OP可以轻松地将变量转换为小写;或者我误解了OP的问题了吗?最好的方法是根本不要做这种愚蠢的验证——因为正则表达式对于许多有效的电子邮件地址都失败了。(至于这个主题到底有多复杂,我建议你做一些研究。)如果你需要用PHP验证电子邮件地址,你应该使用filter\u var
和filter\u validate\u email
@Fred ii-是的,这并不是完全错误的,我同意filter是一种更好的方法。所以我给你们两个一个+1:)~我同意strtolower(),如果它存储在一个数据库中,但是OP只是用它发送电子邮件,所以它不需要修改,只需要通过验证。当然,很高兴我能帮上忙。
$email_address = $_POST["contact_email"];
$email_address = strtolower($_POST["contact_email"]);
$email_address = strtolower($_POST["contact_email"]);
if(!filter_var($email_address, FILTER_VALIDATE_EMAIL))
{
echo "E-mail is not valid"; exit;
}