How to Make a button send an email using AS3 automatically

佐手、 提交于 2019-12-04 13:22:51

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 = "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);

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

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