Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Intermediate
Oct 14, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Mailto Subject Changes

It's possible to create mailto links that include a subject line in addition to just the recipient's e-mail address, however, not all e-mail programs support this functionality. That said, to create a new e-mail message with the subject and CC fields filled in you can use a URL formatted like this:
To get the functionality you're looking for, use JavaScript to assemble a URL like the one above from the user's selections on the form. Then set the window's location property to that URL. If this was a normal URL, the browser would display in the main window. However, because this is a mailto link, a new window is automatically opened for the e-mail message, while the current page remains visible.
function doMail() {
	var subj;
	var gourl;

	email = "someone@bigcorp.com";
	subj = document.forms.mailform.subject.options[document.forms.mailform.subject.selectedIndex].value;
	cc = "anyone@othercompany.com";
	gourl = "mailto:" + email + "?subject=" + subj + "&cc=" + cc;

	window.location = gourl;

<FORM NAME="mailform">
<SELECT NAME="subject">
	<OPTION VALUE="Info">Information request</OPTION>
	<OPTION VALUE="Tech. Support">Technical support</OPTION>
	<OPTION VALUE="Comments">Comment</OPTION>
<INPUT TYPE="BUTTON" VALUE="Send Mail" OnClick="doMail()">

Boris Feldman
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date