发布数据不会来

编程入门 行业动态 更新时间:2024-10-27 10:21:59
本文介绍了发布数据不会来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

更新两个:进行一些测试后,我发现在页面中加载jQuery时,它不会起作用。我的网页依赖于jQuery,那我该怎么办?

Update Two: After doing some testing, I found that it does not work when jQuery is loaded in the page. My page relies on jQuery, so what should I do?

更新:你可以在这里看到有问题的页面 here ,以及工作测试页这里。

Update: You can see the problematic page here here, and the working test page here.

我正在制作联系表单,看起来像这样

I'm making a contact form, and it looks like this

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="../sendemail.php"> <div class="row-fluid"> <div class="span5"> <label>First Name</label> <input name="first" type="text" class="input-block-level" required="required" placeholder="Your First Name"> <label>Last Name</label> <input name="last" type="text" class="input-block-level" required="required" placeholder="Your Last Name"> <label>Email Address</label> <input name="email" type="text" class="input-block-level" required="required" placeholder="Your email address"> </div> <div class="span7"> <label>Message</label> <textarea name="message" id="message" required class="input-block-level" rows="8"></textarea> </div> </div> <button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button> <p> </p> </form>

没有什么太花哨。 sendemail.php看起来像这样

Nothing too fancy. sendemail.php looks like this

<?php header('Content-type: application/json'); $status = array( 'type'=>'success', 'message'=>'Email sent!' ); $name = @trim(stripslashes($_POST['first']." ".$_POST['last'])); $email = @trim(stripslashes($_POST['email'])); $subject = "Monarc - Message From ".$name; $message = @trim(stripslashes($_POST['message'])); $email_from = $email; $email_to = 'xxx@xxx.xxx'; $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message; $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>'); echo json_encode($status); die;

电子邮件通过,但postdata不会在电子邮件中通过。它表示(未知的发件人)作为发件人,身体看起来像这样:

The email comes through, but the postdata isn't coming through in the email. It says (unknown sender) as the sender, and the body looks like this:

名称:

Name:

电子邮件:

主题:Monarc - 来自

Subject: Monarc - Message From

消息:

我做错了什么?

谢谢!

推荐答案

补充信息,此表格使用以下JavaScript文件:

supplementary information, this form uses the following javascript file:

jQuery(function($){

jQuery(function($) {

// Ajax contact var form = $('。contact-form'); form.submit(function {$ this = $(this); $ .post($(this).attr('action'), function(data){ $ this.prev() ).fadeIn()。delay(3000).fadeOut(); },'json'); return false;});

//Ajax contact var form = $('.contact-form'); form.submit(function () { $this = $(this); $.post($(this).attr('action'), function(data) { $this.prev().text(data.message).fadeIn().delay(3000).fadeOut(); },'json'); return false; });

// Goto顶部$('。gototop')。click(function(event){ event.preventDefault(); $('html,body')。animate({ scrollTop:$(body)。offset()。top},500); }); //结束goto top

//Goto Top $('.gototop').click(function(event) { event.preventDefault(); $('html, body').animate({ scrollTop: $("body").offset().top }, 500); }); //End goto top

});

在另一个论坛上搜索我发现如何解决这个问题。您只需在php文件中添加以下代码:

Searching on another forum I found how to fix this. You only need add the following code in the php file:

$headers = "From: mail <$email_from>\r\n"; $headers .= "MIME-Version: 1.0" ."\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

并删除$ success = @mail的@($ email_to,$ subject,$ body, 'from:<'。$ email_from。'>');

and remove "@" of $success = @mail($email_to, $subject, $body,'From: <'.$email_from.'>');

在main.js文件中,您的代码不提供.post中的任何数据) 方法。您需要添加$(this).serialize()以获取所有表单字段/值。

In "main.js" file your code isn't supplying any data in the .post() method. you need to add $(this).serialize() to get all the form fields/values.

未经测试但应该工作 -

untested but should work -

$。post($(this).attr('action'),$(this).serialize(),function(data){

$.post($(this).attr('action'),$(this).serialize(), function(data) {

希望有助于解决问题

更多推荐

发布数据不会来

本文发布于:2023-10-12 00:22:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483258.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会来   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!