wordpress ajax 参数,为什么当在Wordpress上使用Ajax传递参数时出现“500 Internal Server Error”错误?...

子车宏浚
2023-12-01

这是HTML结构:

Name:
E-mail:
Message:
Submit

我有一个从HTML抓住输入,并将其发送到content.php文件我有我的twentyfifteen,儿童主题的功能。

// Send button for the "contact form".

jQuery('#sendBtn').click(function(){

//get info

var fullname = jQuery("#fullname").val();

var email = jQuery("#email").val();

var text = jQuery("#text").val();

//send info to php

jQuery.ajax({

beforeSend: function() {

if (IsEmail(email) == false) {

jQuery('#aboutUnsuccess').show("slow");

/*jQuery('#pixel-thing').show("fast");*/

jQuery('.form_content').hide("slow");

}

},

url: 'http://54.149.xx.xx/wp-content/themes/twentyfifteen-child/contact.php',

type: "POST",

data: ({ "fullname": fullname, "email": email, "text": text }),

success: function (results){

if (IsEmail(email) == true) {

//hide table

jQuery('.form_content').hide('slow', function() {

jQuery('.form_content').hide("slow");

});

//show textboxes

jQuery('#aboutSuccess').show("slow");

jQuery("#aboutSuccess").append("");

/************************************/

window.google_trackConversion({

google_conversion_id: 666,

google_remarketing_only: true

});

/*************************************/

}

}

});

最后我content.php处理参数和相关信息发送到我的邮箱:

require_once "Mail.php";

if(isset($_POST['email'])) {

$email = $_POST['email'];

$email_to = "[email protected]";

$host = "ssl://smtp.gmail.com:465";

$username = '[email protected]';

$password = 'passpaspaspas';

$email_subject = "You have a new email from $email via example.com website";

$message = $_POST['text'];

$headers = array ('From' => $email, 'To' => $email_to,'Subject' => $email_subject);

$smtp = Mail::factory('smtp',

array ('host' => $host,

'auth' => true,

'username' => $username,

'password' => $password));

$mail = $smtp->send($email_to, $headers, $message);

if (PEAR::isError($mail)) {

echo($mail->getMessage());

} else {

echo("Message successfully sent!\n");

}

}

我感动我的网站,这是没有任何MVC/CMS构建,使用WordPress。这适用于我的“常规”网站。

为什么我的代码在wordpress中无法使用?

这是铬合金“网络”输出:

Remote Address:54.159.xx.xx:80

Request URL:http://54.159.xx.xx/wp-content/themes/twentyfifteen-child/contact.php

Request Method:POST

Status Code:500 Internal Server Error

Request Headersview source

Accept:*/*

Accept-Encoding:gzip, deflate

Accept-Language:en-US,en;q=0.8

Connection:keep-alive

Content-Length:63

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

Cookie:wp-settings-1=editor%3Dtinymce%26posts_list_mode%3Dlist; wp-settings-time-1=1424359234

Host:54.149.xx.xx

Origin:http://54.149.xx.xx

Referer:http://54.149.xx.xx/?page_id=73

User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36

X-Requested-With:XMLHttpRequest

Form Dataview sourceview URL encoded

fullname: Test

email:[email protected]

text:This is a test

Response Headersview source

Connection:close

Content-Length:0

Content-Type:text/html

Date:Tue, 24 Feb 2015 14:13:46 GMT

Server:Apache/2.4.7 (Ubuntu)

X-Powered-By:PHP/5.5.9-1ubuntu4.5

 类似资料: