Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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
Javascript 表单表明它已发送,但我未收到任何信息_Javascript_Php_Html_Forms - Fatal编程技术网

Javascript 表单表明它已发送,但我未收到任何信息

Javascript 表单表明它已发送,但我未收到任何信息,javascript,php,html,forms,Javascript,Php,Html,Forms,我的表格有一个问题,我似乎无法解决,我希望这里有人能帮我。请参阅下面的代码 这是检查和发送代码,我遗漏了一些东西 <script type="text/javascript"> header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); $admin_em

我的表格有一个问题,我似乎无法解决,我希望这里有人能帮我。请参阅下面的代码

这是检查和发送代码,我遗漏了一些东西

<script type="text/javascript">

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

$admin_email = 'myemail@gmail.com'; // Your Email
$message_min_length = 5; // Min Message Length


class Contact_Form{
    function __construct($details, $email_admin, $message_min_length){

        $this->name = stripslashes($details['name']);
        $this->email = trim($details['email']);
        $this->subject = 'Massage'; // Subject 
        $this->message = stripslashes($details['message']);

        $this->email_admin = $email_admin;
        $this->message_min_length = $message_min_length;

        $this->response_status = 1;
        $this->response_html = '';
    }


    private function validateEmail(){
        $regex = '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';

        if($this->email == '') { 
            return false;
        } else {
            $string = preg_replace($regex, '', $this->email);
        }

        return empty($string) ? true : false;
    }


    private function validateFields(){
        // Check name
        if(!$this->name)
        {
            $this->response_html .= '<p>name please</p>';
            $this->response_status = 0;
        }

        // Check email
        if(!$this->email)
        {
            $this->response_html .= '<p>email please</p>';
            $this->response_status = 0;
        }

        // Check valid email
        if($this->email && !$this->validateEmail())
        {
            $this->response_html .= '<p>email not right</p>';
            $this->response_status = 0;
        }

        // Check message length
        if(!$this->message || strlen($this->message) < $this->message_min_length)
        {
            $this->response_html .= '<p>To short please more then '.$this->message_min_length.' characters</p>';
            $this->response_status = 0;
        }
    }


    private function sendEmail(){
        $mail = mail($this->email_admin, $this->subject, $this->message,
             "Van: ".$this->name." <".$this->email.">\r\n"
            ."Reageer op: ".$this->email."\r\n"
        ."X-Mailer: PHP/" . HTMLversion());

        if($mail)
        {
            $this->response_status = 1;
            $this->response_html = '<p>E-mail send</p>';
        }
    }


    function sendRequest(){
        $this->validateFields();
        if($this->response_status)
        {
            $this->sendEmail();
        }

        $response = array();
        $response['status'] = $this->response_status;   
        $response['html'] = $this->response_html;

        echo json_encode($response);
    }
}
$contact_form = new Contact_Form($_POST, $admin_email, 
$message_min_length);
$contact_form->sendRequest();

 </script>

标头('Cache-Control:无缓存,必须重新验证');
页眉(‘到期日期:1997年7月26日星期一05:00:00 GMT’);
标题('Content-type:application/json');
$admin\u电子邮件地址:myemail@gmail.com'; // 你的电子邮件
$message_min_length=5;//最小消息长度
班级联络表{
函数构造($details、$email\u admin、$message\u min\u length){
$this->name=stripslashes($details['name']);
$this->email=trim($details['email']);
$this->subject=‘按摩’;//subject
$this->message=stripslashes($details['message']);
$this->email\u admin=$email\u admin;
$this->message\u min\u length=$message\u min\u length;
$this->response\u status=1;
$this->response_html='';
}
私有函数validateEmail(){
$regex='/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})$/i';
如果($this->email=''){
返回false;
}否则{
$string=preg_replace($regex,,$this->email);
}
返回空($string)?true:false;
}
私有函数validateFields(){
//核对姓名
如果(!$this->name)
{
$this->response_html.='请说出姓名

'; $this->response\u status=0; } //查看电子邮件 如果(!$this->email) { $this->response_html.='请发送电子邮件

'; $this->response\u status=0; } //检查有效电子邮件 如果($this->email&&!$this->validateEmail()) { $this->response_html.='电子邮件不正确

'; $this->response\u status=0; } //检查消息长度 如果(!$this->message | | strlen($this->message)<$this->message_min_length) { $this->response_html.='要短一些,请多点。$this->message_minu_length.'characters

; $this->response\u status=0; } } 私有函数sendmail(){ $mail=mail($this->email\u admin,$this->subject,$this->message, “Van:”.$this->name.\r\n” “Reageer op:”.$this->电子邮件。“\r\n” “X-Mailer:PHP/”.HTMLversion()); 如果($邮件) { $this->response\u status=1; $this->response_html='电子邮件发送

'; } } 函数sendRequest(){ $this->validateFields(); 如果($this->response\u status) { $this->sendmail(); } $response=array(); $response['status']=$this->response\u status; $response['html']=$this->response\u html; echo json_编码($response); } } $contact\u form=新联系人表单($\u POST,$admin\u email, $message_min_length); $contact_form->sendRequest();
这是我用来检查和发送电子邮件的脚本

<form id="contact-form" class="contact-form" action="/contact.html" target="_self" method="post"
    <p class="contact-name">
        <input id="contact_name" type="text" placeholder="Full Name" value="" name="name" />
    </p>
    <p class="contact-email">
        <input id="contact_email" type="text" placeholder="Email Address" value="" name="email" />
    </p>
    <p class="contact-message">
        <textarea id="contact_message" placeholder="Your Message" name="message" rows="15" cols="40"></textarea>
    </p>
    <p class="contact-submit">
        <a style="color: white;" id="contact-submit" class="submit" value="submit">Send Your Email</a>
    </p>

    <div id="response">

    </div>
</form>

看起来您的php代码包含在
标记中,但您应该使用


此外,表单的开始标记缺少一个

似乎您正在HTML脚本标记中使用PHP,其类型属性设置为“text/javascript”

试一试

<script language=php>
    ...Your code here...
</script>

…你的代码在这里。。。

或者使用基本的php标记,表单上的操作是一个HTML文件,它将不起任何作用

您需要表单处理脚本是一个php文件(我假设您的服务器已经能够处理php),表单上的操作应该是

<form id="contact-form" class="contact-form" action="/contact.php" target="_self" method="post">


请注意,我还在post后添加了结束“>”标志,因为标签仍然打开。

据我所知,
Van
Reageer op
是不可识别的电子邮件标题。也许你的意思是来自
和回复
?大多数电子邮件服务(如GMail)可能会拒绝接收带有这些奇怪标题的电子邮件。为您的域设置DKIM和SPF记录也是一个好主意。当您执行代码时,它以什么方式工作?
$mail
是否正确?如果是这样的话,请检查您的垃圾邮件文件夹和邮件服务器日志。让我检查一下,然后再联系您。无论如何,我不能使用.PHP,我只能使用.HTML,谢谢您的更正。@D.Man据我所知,在没有.PHP扩展名的文件中使用PHP是不可能的。你不能使用.php文件的原因是什么?当我打开时,它会将孔文件更改为文本it@D.Man听起来好像你试图从电脑而不是服务器上运行文件。您需要首先安装xampp,然后在那里运行.php文件。网上有很多这方面的教程。这将是一个漫长的过程,我将只添加信息和谷歌地图。谢谢你的帮助,很抱歉浪费了大家的时间!因此,我很高兴将hole文件从.html更改为.php。现在我需要找出文件工作不正常的原因。。。