如何从AIR桌面应用程序中发送电子邮件?

时间:2015-05-15 10:39:53

标签: php actionscript-3 flash email air

我正在尝试允许用户从AIR桌面应用程序中发送电子邮件。 起初我试过了:

navigateToURL(newURLRequest("mailto:someone@example.comSubject=Hello&Body=SomeText");

但这会在默认的互联网浏览器中打开一个空标签。

然后我尝试使用php文件,我将其上传到服务器上。 PHP代码是:

<?php
$to = ($_POST['recipientEmail']);
$subject = ($_POST['SenderName']);
$message = ($_POST['senderMesssage']);
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] .     ">\n";
if(@mail($to, $subject, $message, $headers))
{
    echo "answer=ok";
} 
else 
{
    echo "answer=error";
}
?>

并将其上传到以下地址:     http://xespoofer.comxa.com/mail.php

动作方面是:

var myVars:URLVariables = new URLVariables();
myVars.senderName = settings.companyName;
myVars.senderEmail =String(settings.settingsXML.Setting.@senderEmail);;
myVars.senderMesssage = String(settings.settingsXML.Setting.@Message);
myVars.recipientEmail = String(settings.settingsXML.Setting.@email);

var myURL:URLRequest = new URLRequest("http://xespoofer.comxa.com/mail.php");
myURL.method = URLRequestMethod.POST;
myURL.data = myVars;

var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(myURL);

单击按钮时会运行actionscript代码。问题是没有任何反应。电子邮件未发送。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我建议你添加一些监听器来检测发生了什么。 我刚试过(使用硬编码字符串,你应该替换使用你正确的数据):

var myVars:URLVariables = new URLVariables();
myVars.senderName = "name";
myVars.senderEmail =String("email@email.com");;
myVars.senderMesssage = String("Message");
myVars.recipientEmail = String("email2@email.com");

var myURL:URLRequest = new URLRequest("http://xespoofer.comxa.com/mail.php");
myURL.method = URLRequestMethod.POST;
myURL.data = myVars;

var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
myLoader.load(myURL);

function completeHandler(event:Event):void
{
    trace("completeHandler: ", URLLoader(event.target).data.toString());
}

function progressHandler(event:ProgressEvent):void
{
    trace("progressHandler");
}

function ioErrorHandler(event:IOErrorEvent):void
{
    trace("ioErrorHandler");
}

completeHandler方法输出:&#34; answer=ok&#34;。使用您的真实数据对其进行调试,并检查您是否将正确的值传递给senderNamesenderEmailsenderMessagerecipientEmail