我无法使用.php发送消息。
奇怪的是,我已经测试并且能够在过去发送消息,但由于某种原因,我现在收到消息' *消息字段必须只包含字母,数字,空格和基本标点符号(&#39 ; - ,。),限制为1000个字符&不应该留空。 '
我知道它是由于消息格式和.php中的冲突导致的消息,但是没有技能来纠正它。
我建立了一个网站,使用相同的联系人& .php形式,也有同样的问题。
请告知:
<?php
$your_email = "mailto@host.com"; // email address to which the form data will be sent
$subject = "Subject Here"; // subject of the email that is sent
$thanks_page = "/thankyou/"; // path to the thank you page following successful form submission
$contact_page = "http://test.com/contact/index.html"; // path to the HTML contact page where the form appears
if (!isset($_POST['submit'])) {
header( "Location: $contact_page" );
}
if (isset($_POST["submit"])) {
$nam = $_POST["name"];
$ema = trim($_POST["email"]);
$mes = $_POST["message"];
$spa = $_POST["spam"];
if (get_magic_quotes_gpc()) {
$nam = stripslashes($nam);
$ema = stripslashes($ema);
$mes = stripslashes($mes);
}
$error_msg=array();
if (empty($nam) || !preg_match("~^[a-z\-'\s]{1,60}$~i", $nam)) {
$error_msg[] = "<br/>* The name field must contain only letters, spaces, dashes ( - ) and single quotes ( ' ).\n<br />\n<br />";
}
if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) {
$error_msg[] = "<br/>* Your email must have a valid format, such as name@mailhost.com\n<br />\n<br />";
}
$limit = 1000;
if (empty($mes) || !preg_match("/^[0-9A-Za-z\/-\s'\(\)!\?\.,]+$/", $mes) || (strlen($mes) > $limit)) {
$error_msg[] = "<br/>* The Message field must contain only letters, digits, spaces and basic punctuation ( ' - , . ), has a limit of 1000 characters & should not be left empty.\n<br />\n<br />";
}
if (!empty($spa) && !($spa == "4" || $spa == "four")) {
echo "* You failed the spam test! Please go back and try again.\n<br />\n<br />";
exit ();
}
if ($error_msg) {
echo '<!--CONTACT--->
<!DOCTYPE html>
<!--[if lt IE 7]><html lang="en-US" class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->
<!--[if IE 7]><html lang="en-US" class="no-js lt-ie9 lt-ie8"><![endif]-->
<!--[if IE 8]><html lang="en-US" class="no-js lt-ie9"><![endif]-->
<!--[if gt IE 8]><!--><html lang="en-US" class="js"><!--<![endif]-->
<head>
</head>
<body>
</body>
</html>';
exit();
}
$email_body =
"Name of Sender: $nam\n\n" .
"Email: $ema\n\n" .
"Message:\n\n" .
"$mes" ;
if (isset($_REQUEST['message']) && !$error_msg) {
mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To: $nam <$ema>");
header ("Location: $thanks_page");
exit();
}
}
可以在此处尝试联系表单工作不正确的示例 - http://mickscaricatures.co.uk/contact.html
我是否可以提供任何进一步的信息来帮助解决这种情况?
答案 0 :(得分:0)
你在$ mes参数的正则表达式中错过了一个转义:
[..snip..]\/-\s[..snip..]
^---
由于-
未转义,因此将其视为any chars from slash to space
。