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.

action="mailto:p@yahoo.com?Subject..."

Thanks a lot

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:

formMailer

<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.

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

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".

Airshow

Bufospro,

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.

<script>
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++){
		bodyEscaped.push(escape(body[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';
	document.getElementById('container').appendChild(a);
}
</script>

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).

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.