Skip to main content
Participating Frequently
October 9, 2013
Answered

AS3 mailto

  • October 9, 2013
  • 1 reply
  • 15835 views

Hi


I'm making a contact form so when you click the submit button it opens up a email window were the subject and message is already fill in because they did it in the contact form. I dont really know which code I should use. I've only gotten this far. The subject and message is textinput and textarea components.


var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject=subjectText&body=bodyText" );

bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);

function fEmailClick(event:MouseEvent):void {

navigateToURL(vEmail," _blank" ) ;

}

This topic has been closed for replies.
Correct answer kglad

use:


var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject="+yoursubjecttextfield.text+"&body="+yourmessagetextfield.text );

bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);

function fEmailClick(event:MouseEvent):void {

navigateToURL(vEmail," _blank" ) ;

}

1 reply

kglad
kgladCorrect answer
Community Expert
October 9, 2013

use:


var vEmail:URLRequest = new URLRequest(" mailto:mail@example.com?subject="+yoursubjecttextfield.text+"&body="+yourmessagetextfield.text );

bEmail.addEventListener(MouseEvent.CLICK,fEmailClick);

function fEmailClick(event:MouseEvent):void {

navigateToURL(vEmail," _blank" ) ;

}

Lunkan87Author
Participating Frequently
October 9, 2013

I didnt work. Still dosent load any subject or message into the email. A stupid question do I have to use import flash.net.URLRequest; or something like that for it to work?

Inspiring
October 9, 2013

First, I would encode the subject and body text using encodeURIComponent:

new URLRequest("mailto:email@domain.com?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body));

Secondly, mailto is subject to rather arbitrary and inconsistent limitations across browsers. If the subject or body is too long, for instance, it won't work. In one case where I wanted to provide an error report email feature what I did was copy the text to the clipboard, then simply set the body to "PASTE YOUR CLIPBOARD".

Cheers.

-Aaron