如何使用mailTo发送邮件提交

时间:2017-04-19 19:34:45

标签: javascript html mailto

我对这个snipet有两个问题:

1) for some reason the body is not updating with the innerHTML of #test

2) The client's email is coming up on the SHARE link but I can't get it to open on submit

function Mailto_url(){
	var encode_mailto_component = function(str){
		try{ return encodeURIComponent(str); }
		catch(e){ return escape(str); }
	}
	var AddressList = function(){
		var list = [];
		this.length = 0;
		this.add = function(address){
			if(address) {
				list.push(address);
				this.length = list.length;
			}
		};
		this.get = function(){
			return list.join(';');
		};
	};
	var subject = '',
		body = '',
		mainList = new AddressList(),
		ccList = new AddressList(),
		bccList = new AddressList();
	this.setSubject = function(str){ subject = encode_mailto_component(str); }
	this.setBody = function(str){ body = encode_mailto_component(str); }
	this.addMain = function(x) { mainList.add(x); }
	this.addCC = function(x) { ccList.add(x); }
	this.addBCC = function(x) { bccList.add(x); }
	this.getURL = function(allow_empty_mainList){
		var out = ['mailto:'];
		var extras = [];
		if(mainList.length === 0 && !allow_empty_mainList){
			throw('Mailto_url: no main addressees');
		}
		else{
			out.push(mainList.get());
		}
		if(subject) { extras.push('subject=' + subject); }
		if(ccList.length) { extras.push('cc=' + ccList.get()); }
		if(bccList.length) { extras.push('bcc=' + bccList.get()); }
		if(body) { extras.push('body=' + body); }
		if(extras.length) { out.push('?' + extras.join('&')); }
		return out.join('');
	}
}

function getContent() {
	var mailTo = new Mailto_url();
  var test = document.getElementById('test');
mailTo.addMain('rssxyze@gmail.com');
mailTo.addMain('mrsairshow@ddd.net');
mailTo.addCC('linda@xyz.com');
mailTo.addCC('mandy@abc.com');
mailTo.addBCC('susanne@mno.com');
mailTo.addBCC('chris@mno.com');
mailTo.setSubject("test");
mailTo.setBody(test.innerHTML);
window.location=mailTo.getURL(true);
		
	
}
<html>

<body>
  <div id="wrapper">


    <form>
      <ul>
        <li>
          <a class="home" href="#"></a>
        </li>
        <li><a id="share" class="share" href="#" onclick="getContent()">Share Quote</a></li>
        <li>
          <a class="info" href="#"></a>
        </li>
        <li><input id='test' type='text'></input>
        </li>
        <li><input type='submit' onclick="getContent()"></input>
        </li>
      </ul>
    </form>
  </div>


</body>

</html>

2 个答案:

答案 0 :(得分:2)

NSMutableArray* itemsToDelete = [[NSMutableArray alloc] init] 

它不应该是innerHTML它应该是值。 此外,您发布的代码中没有函数调用。

答案 1 :(得分:2)

第2部分

<form onsubmit="return false">

更改此行