Hi all,
first of all I apologise that I write in this category (javascript) but I don't know where I could be helped.

I use a contact form in my site with the fields
user, email, subject, comments

I would like after user's submit to send me all the data
But I don't know how can I define the action because all the fields are like variables.


Thanks a lot

9 Years
Discussion Span
Last Post by Airshow

This is much better if handled in PHP.

If you just want to get bits of data in your form, using PHP.

simply do this format:


<input type="text" id="subject" name="subject" value="" />

now if you want to get the value in the subject input field, then try this code in the after form submitted (PHP) page.

<h1><?php echo $_POST['subject']; ?></h1>
<!-- were [b]subject[/b] is ( id/name ) used in the subject field inside the form mailer -->

hope it helped you a little...


Thanks for your answer, but I think that you did not understand what I mean exactly.

I use 3 input elements and 1 textarea (with ids and names) I want when an user clicks on Submit button to send all the data via Outlook.

Something like :

User : ...
E-mail : ...
Subject : ....
Notes : ...............


Oh, i'm really sorry about that post, i thougth that it was something else.

Maybe you should try this inside the ASP section, am sure all the guys out there can provide you the exact things you need for this query.


I wonder if this is what you want. ....

The mailto URL is defined here. It's not presented in a particularly friendly format and I suggest you go straight to section 6, Examples.

Of the rest, it's probably worth noting that:

  • within mailto URLs, the characters "?", "=", "&" are reserved.
  • line breaks in the body of a message MUST be encoded with "%0D%0A".




Just realised, you probably want a javascript mailto:builder function.

Try the code below in a new .html document- it includes a test function which fires on page load - that bit is just for testing and can be used as an example of how to call the function.

function composeMailTo(to, cc, subject, body){
	if(!to) { alert('No main recipients specified'); return ''; };
	cc = (!cc) ? [] : cc;
	if(typeof to === 'string') { to = to.split(';') };
	if(typeof cc === 'string') { cc = cc.split(';') };
	subject = (!subject) ? '' : escape(subject);
	body = (!body) ? [] : (typeof body === 'string') ? [body] : body;
	var bodyEscaped = [];
	for(var i=0; i<body.length; i++){
	return 'mailto:' +
		'?to=' + to.join("%2C%20") +
		'&cc=' + cc.join("%2C%20") +
		'&subject=' + subject +
		'&body=' + bodyEscaped.join("%0D%0A");
onload = function(){
	//Note : toAddresses and ccAddresses can each be built as arrays or ;-separated strings.
	var toAddresses = ['aaa@yyy.com', 'bbb@zzz.com'];//Array of email addresses
	var ccAddresses = ['ccc@yyy.com;ddd@zzz.com'];//;-separated string of email addresses
	var subject = 'Subject string';//Simple string
	var body = ['line 1', 'line 2', 'line 3'];//Array where each element is a separate line of text

	var a = document.createElement('a');
	a.href = composeMailTo(toAddresses, ccAddresses, subject, body);
	a.innerHTML = 'Send email';

This is off-the-cuff and not very well tested, so may not be too robust. Use with caution.

Now, DON'T go using this for generating spam or your ISP will be down on you like a ton of bricks (and so will I)!!! (By the way, real spammers don't do it this way).


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.