如何将正文从.js页面的文本区域发送到.php页面


how to send a body from a textarea from a .js page to a .php page

我一直在寻找StackOverflow和其他论坛网站,但我仍然不知道如何简化我正在做的事情。

我想在我正在开发的网站上发送个性化的电子邮件(可以是文本或html)。

我使用ajax来发送邮件列表、主题和正文。代码看起来像这个

这是.js

    function loadsentmail(){
var subject = document.getElementById("subject_title").value;
var content = tinyMCE.get('content').getContent();
var from = "somemail@mail.com";
var body = new Array();
body[0]=content;
$.ajax({
type:'POST',
url:'sendmail.php?mails='+mails+'&names='+names+'&idgroup='+idGrupo+'&subject='+subject+'&body='+body+'&from='+from+'&flag=1',
data: {},
            success:function(result){
                alert("Mail sent correctly");
                },
            error:function(){
                alert("Mail was not sent");
            }
});
}

这是.php

$to = $_GET['mails'];
$names = $_GET['names'];
$subject=$_GET['subject'];
$from = $_GET['from'];
$body = $_GET['body'];
$flag=$_GET['flag'];
$groupId=$_GET['idgroup'];
echo $flag;
$headers = "MIME-Version: 1.0'r'n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1'r'n"; 
$headers .= "From: Some Company <somemail@somemail.com>'r'n"; 
$headers .= "Reply-To: somemail@somemail.com'r'n"; 
$headers .= "Return-path: somemail@somemail.com'r'n"; 
$headers .= "Cc: somemail@somemail.com'r'n"; 
$headers .= "Bcc: somemail@somemail.com'r'n";
switch($flag)
{
case 1:
    if (mail($to, $subject,$body,$headers)) {
        echo("<p>Message successfully sent!</p>");
} 
    else {
echo("<p>Message delivery failed...</p>");
    }
break;
} 

到目前为止还不错,我用小机身进行了测试,它很有效,但一旦我粘贴了一个大的html文件,我就得到了以下错误

<h1>Request-URI Too Large</h1>
<p>The requested URL's length exceeds the capacity
limit for this server.<br />
</p>

将一个大Body从.js发送到.php的最佳实践是什么??我在网上搜索了很多,但还是能找到答案。请帮助我:S

$.ajax({
 type:'POST',
 url:'sendmail.php',
 data: {
  mails: mails,
  names: names,
  idgroup: idGrupo,
  subject: subject,
  body: body,
  from: from,
  flag:1
 },
 type: "POST",
 success:function(result){
    alert("Mail sent correctly");
 },
 error:function(){
    alert("Mail was not sent");
  }
});

Post将允许更大的数据集,使用jquery ajax,即使使用GET,也应该使用数据对象发送数据。

此外,我相信(我是一个perl,而不是php开发人员,所以你需要查找它)你需要更改你的php以从Post-obj中抓取。$to = $_GET['mails'];将变为$to = $_POST['mails']