[英]how to send a body from a textarea from a .js page to a .php page
I've been looking all over StackOverflow and other forum sites, but I still don't know how to acomplish what I'm doing. 我一直在寻找StackOverflow和其他论坛站点,但我仍然不知道如何完成我正在做的事情。
I want to send personalized emails (can be text or html) in a website I'm developing. 我想在我正在开发的网站中发送个性化电子邮件(可以是文本或html)。
I'm using ajax to send the list of mails, the subject and the body. 我正在使用ajax发送邮件列表,主题和正文。 The code looks like this 代码看起来像这样
This is the .js 这是.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");
}
});
}
This is the .php 这是.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;
}
So far so good, I tested with small body, and it worked, but once I pasted a big html file, I got the following error 到目前为止一切顺利,我用小巧的机身进行了测试,并且可以正常工作,但是一旦粘贴了一个大的html文件,就会出现以下错误
<h1>Request-URI Too Large</h1>
<p>The requested URL's length exceeds the capacity
limit for this server.<br />
</p>
What is the best practice to send a big Body from a .js to a .php?? 将大型主体从.js发送到.php的最佳实践是什么? I've search a lot throughout the internet but I still can find an answer. 我在互联网上进行了大量搜索,但仍然可以找到答案。 Please help me :S 请帮我: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 will allow the larger data set and with jquery ajax you should send the data using the data object even if you use GET. Post将允许更大的数据集,并且使用jquery ajax,即使使用GET,也应使用数据对象发送数据。
Also I believe (I'm a perl not a php dev so you will need to look this up) you will need to change your php to grab from the Post obj. 我也相信(我不是Perl,不是php开发人员,因此您需要进行查找)您需要更改您的php以从Post obj获取。 $to = $_GET['mails'];
will become $to = $_POST['mails']
将变成$to = $_POST['mails']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.