如何在提交时使用mailTo发送邮件

如何在提交时使用mailTo发送邮件

我在此摘要有两个问题:

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('[email protected]');
mailTo.addMain('[email protected]');
mailTo.addCC('[email protected]');
mailTo.addCC('[email protected]');
mailTo.addBCC('[email protected]');
mailTo.addBCC('[email protected]');
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部分

<form onsubmit="return false">


改变这行

关于javascript - 如何在提交时使用mailTo发送邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43504592/

10-12 03:04