views:

2199

answers:

2

I am working in actionscript 3.0 and am making a website!

In my website, I want to make a button that sends an email using a click of button and I don't want it to open their mail client, instead just send it.

I am currently using the "mailto" function but would like to know how to make it send automatically, or what else I can use to achieve that.

Here is a snippet of my code:

function submitPoll(e:MouseEvent):void {

  //sending the email stuff
  var request:URLRequest = new URLRequest("mailto:[email protected]"+"?subject=Subject"+"&body= Hello world ");
  navigateToURL(request, "_blank"); 
  request.method = URLRequestMethod.POST;

  //other

  Submit_btn.x = -100;

  pollUsed = true;
  thanks_txt.x = 849;
  thanks_txt.y = 656;

}
A: 

I think its a case of doing a URLRequest to another PHP file. Send the values of the textfield to the PHP file and process the email that way.

I don't have any code to hand, but this is what I did when I was doing the same. Hope this helps... and don't forget to validate :)

Tisch
+3  A: 

Hi Jackson,

The situation with Flash is more or less the same as the situation with HTML when it comes to sending email. You have 2 options:

  1. Pop open the email client on the users machine using mailto as you are doing.
  2. Send a POST or GET request to a server which can send the email on your behalf.

What you want to do is number 2 so that means you need access to a server capable of sending mail that can also receive GET/POST requests. If you have script access to your webserver you can undoubtedly find a free online script that will allow you to send emails. For example:

How you send the information to the script will depend on what variables the script requires you to send. From ActionScript you will probably want to use URLLoader:

const SCRIPT_URL:String = "http:// .... your server ... / ... script file ...";
var request:URLRequest = new URLRequest(SCRIPT_URL);
var variables:URLVariables = new URLVariables();

// these depend on what names the script expects
variables.email = "[email protected]";
variables.subject = "Subject";
variables.body = "Hello World";

request.data = variables;

// depends if the script uses POST or GET
// adjust accordingly
request.method = URLRequestMethod.POST;

var urlLoader:URLLoader = new URLLoader();
loader.load(request);
James Fassett
thank you so much! I will try this!