简体   繁体   English

如何将正文从.js页发送到.php页

[英]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']

如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 html 获取和发送值<textarea>&lt;i&gt;to a PHP page?&lt;/div&gt;&lt;/i&gt;&lt;b&gt;到 PHP 页面?&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我创建了一个用于图像上传的表单。 此表单还包括一个标签,用于添加有关正在上传的图像的信息。 每当单击“上传”按钮时,我都需要将标签中的文本发送到页面“savetofile.php”。</p><p> 目前图片上传正常,图片信息发送正确,但我无法从“savetofile.php”页面的标签中获取文本。</p><p> 形式</p><pre>&lt;form action="savetofile.php" enctype="multipart/form-data" id="form1" method="post"&gt; &lt;div&gt; &lt;label for="fileToUpload"&gt;Take or select photo(s)&lt;/label&gt;&lt;br/&gt; &lt;input accept="image/*" capture id="fileToUpload" name="fileToUpload" onchange="fileSelected();" type="file"/&gt; &lt;/div&gt; &lt;div&gt; &lt;br&gt;&lt;br&gt; &lt;label for="notes"&gt;Notes:&lt;/label&gt; &lt;textarea cols="50" id="notes" maxlength="2000" name="notes" placeholder="Please enter any additional information here" rows="4" onchange="this.form.submit()"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; &lt;div id="details"&gt;&lt;/div&gt; &lt;div&gt; &lt;input onclick="uploadFile()" type="button" value="Upload"/&gt; &lt;/div&gt; &lt;div id="progress"&gt;&lt;/div&gt; &lt;/form&gt;</pre><p> 保存到文件.php</p><pre> $text = $_POST['notes']; _log('text: '.$text);</pre><p> 上传文件()</p><pre> function uploadFile() { var fd = new FormData(); var count = document.getElementById('fileToUpload').files.length; for (var index = 0; index &lt; count; index++) { var file = document.getElementById('fileToUpload').files[index]; fd.append('myFile', file); } var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.addEventListener("load", uploadComplete, false); xhr.addEventListener("error", uploadFailed, false); xhr.addEventListener("abort", uploadCanceled, false); xhr.open("POST", "savetofile.php"); xhr.send(fd); }</pre><p> 当前 output:</p><pre> Undefined index: notes... text:</pre></div> - How to get and send values from html <textarea> to a PHP page? 使用CSS按钮将信息从文本字段/文本区域发送到另一个PHP页面 - Send information from a textfield/textarea to another php page with a css button 如何从文本区域获取输入的文本并使用PHP在另一个页面上显示它? - How to take inputted text from a textarea and display it on another page with PHP? 将文本从带有 AJAX 的文本区域传递到 PHP 页面? - Passing text from textarea with AJAX to PHP page? 如何将数据从ASPX发送到PHP页面 - How to send data from aspx to php page 如何通过文本验证将html页面中的值发送到php页面 - How to send a value from a html page to php page with text validation 如何使用PHP将图像从一页发送到另一页 - How to send an image from one page to another page using PHP 如何将变量从php页面发送到另一个页面 - How to Send Variable from php page to another page 如何从 php 中的 suneditor textarea 发送值? - How to send value from suneditor textarea in php? 如何从PHP生成的HTML页面获取正文内容? - How to get the body content from a PHP-generated HTML page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM