Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ReferenceError:$未在sendmail.php中定义_Php_Jquery_Sendmail_Contact Form - Fatal编程技术网

ReferenceError:$未在sendmail.php中定义

ReferenceError:$未在sendmail.php中定义,php,jquery,sendmail,contact-form,Php,Jquery,Sendmail,Contact Form,请允许我提前道歉,我只是像昨天一样开始使用jquery,所以请慢慢说,并使用许多初学者术语。无论如何,我试图让我的jquery/ajax联系人表单停止刷新并停留在同一页面上,但我一直收到一个错误,读到“ReferenceError:$未定义”。我试图解决这个问题,并找出它是否与我在这里的失败有关 这是HTML <div id="contact"> <h2>Contact</h2> <div class="c

请允许我提前道歉,我只是像昨天一样开始使用jquery,所以请慢慢说,并使用许多初学者术语。无论如何,我试图让我的jquery/ajax联系人表单停止刷新并停留在同一页面上,但我一直收到一个错误,读到“ReferenceError:$未定义”。我试图解决这个问题,并找出它是否与我在这里的失败有关

这是HTML

<div id="contact">
            <h2>Contact</h2>
            <div class="clear"></div>
            <div class="contactContainer">
                <h3>Get in touch:</h3>
                <div class="contact">

                    <form action="js/ajaxcontactform/sendmail.php" method="post" id="contactForm">
                    <ul>
                    <li>
                    <label for="name">Name:<font color="#ff3300">*</font></label>
                    <input type="text" name="name" value="" id="name" />
                    </li>
                    <li>
                    <label for="email">Email:<font color="#ff3300">*</font></label>
                    <input type="text" name="email" value="" id="email" />
                    </li>
                    <li>
                    <label for="tele">Telephone:</label>
                    <input type="text" name="tele" value="" id="tele" />
                    </li>
                    <li class="special" style="display: none;">
                    <label for="last">Don't fill this in:</label>
                    <input type="text" name="last" value="" id="last" />
                    </li>
                    <li>
                    <label for="message">Message:<font color="#ff3300">*</font></label><textarea rows="5" name="message"></textarea>
                    </li>
                    <li class="submitbutton">
                    <input type="submit" class="btn" value="Send Message" />
                    </li>
                    </ul>
                    </form>

接触
联系:
  • 姓名:*
  • 电邮:*
  • 电话:
  • 不要填写以下内容:
  • 信息:*
这是php

    <?php

// basic settings section
$sendto = 'your@email.com';
$subject = 'You have a new message from your virtual resume!';
$iserrormessage = 'There was a problem with sending e-mail to us, please check:';
$thanks = "Thank's for your message! I'll contact you as soon as possible!";

$emptyname = 'Did you enter your name?';
$emptyemail = 'Did you enter your e-mail address?';
$emptymessage = 'Did you enter the message?';
$emptyphone = 'Did you enter phone number?';

$alertname = 'Please enter your name with standard alphabet!';
$alertemail = 'Please enter your e-maill address in format: name@domain.com';
$alertmessage = "Please do not use any parenthesis or other escaping characters. Standard web url's should work fine!";
$alertphone = 'Please enter your phone number without any special characters, only numbers ex: 5553212';

$alert = '';
$iserror = 0;

// cleaning the post variables
function clean_var($variable) {$variable = strip_tags(stripslashes(trim(rtrim($variable))));return $variable;}

// validation of filled form
if ( empty($_REQUEST['name']) ) {
$iserror = 1;
$alert .= "<li>" . $emptyname . "</li>";
} elseif ( ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] ) ) {
$iserror = 1;
$alert .= "<li>" . $alertname . "</li>";
}


if ( empty($_REQUEST['email']) ) {
$iserror = 1;
$alert .= "<li>" . $emptyemail . "</li>";
} elseif ( !eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $_REQUEST['email']) ) {
$iserror = 1;
$alert .= "<li>" . $alertemail . "</li>";
}

if ( empty($_REQUEST['message']) ) {
$iserror = 1;
$alert .= "<li>" . $emptymessage . "</li>";
} elseif ( ereg( "[][{}*+\\^|]", $_REQUEST['message'] ) ) {
$iserror = 1;
$alert .= "<li>" . $alertmessage . "</li>";
}

// if there was error, print alert message
if ( $iserror==1 ) {

echo "<script type='text/javascript'>$(\".message\").hide(\"slow\").fadeIn(\"slow\").delay(5000).fadeOut(\"slow\"); </script>";
echo "<strong>" . $iserrormessage . "</strong>";
echo "<ul>";
echo $alert;
echo "</ul>";

} else {
// if everything went fine, send e-mail

$msg = "From: " . clean_var($_REQUEST['name']) . "\n";
$msg .= "Email: " . clean_var($_REQUEST['email']) . "\n";
$msg .= "Message: \n" . clean_var($_REQUEST['message']);
$header = 'From:'. clean_var($_REQUEST['email']);

mail($sendto, $subject, $msg, $header);

echo "<script type='text/javascript'>$(\".message\").fadeOut(\"slow\").fadeIn(\"slow\").animate({opacity: 1.0}, 5000).fadeOut(\"slow\");</script>";
echo $thanks;

die();
}
?>

是否导入jquery库?
试着把它放在你的代码头上

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

查看您的实际站点,我发现在您指定的文件夹中并没有找到JS包含的所有内容。尤其是
jquery.form.js
的情况。由于找不到此插件,因此当您提交表单时,页面会自然刷新

查看HTML,我发现这一行:

<script type="text/javascript" src="/js/ajaxcontactform/jquery.form.js"></script>
注意
src
开头缺少的
/

编辑:


另外,在包含主jQuery库之后,还需要加载插件。

ereg折旧了,我想你是从某个网站上得到的,找一个更新的。是的,它就在那里。仍然显示错误,并且在发送消息时仍然离开页面:(您是否查看了控制台…我看到了几个错误,最重要的是服务器上没有找到
jquery.form.js
(或者至少在您提供的位置没有找到)。是的,它确实上传了。不知道你为什么看不到它。它在我的js文件夹中。它可能会被上传,但在你将浏览器指向的地方找不到它……你是说你没有收到控制台错误吗?@DarinSD你是在jquery.form.js之前调用jquery库的吗??
<script type="text/javascript" src="js/ajaxcontactform/jquery.form.js"></script>