How to Make a button send an email using AS3 automatically

无人久伴 提交于 2019-12-06 08:48:23

问题


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:name@hotmail.com"+"?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;

}

回答1:


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:

  • PHP
  • Python
  • Ruby
  • Perl
  • ASP

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 = "name@hotmail.com";
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);



回答2:


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



来源:https://stackoverflow.com/questions/1364958/how-to-make-a-button-send-an-email-using-as3-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!