2015-01-06 87 views
0

我使用閃光燈CS6和Flash Player 11.4AS3發送使用PHP

這裏電子郵件的例子從發送電子郵件閃存使用PHP

AS3代碼:

var php_file = "simple_email.php"; 
var message_text = "Hello Im mesage from flash."; 

function sendEmail():void 
{ 
    var myData:URLVariables = new URLVariables(); 
    myData.msg = message_text; 

    var myRequest:URLRequest = new URLRequest(php_file); 
    myRequest.data = myData; 
    myRequest.method = URLRequestMethod.POST; 

    var loader:URLLoader = new URLLoader(); 
    loader.dataFormat = URLLoaderDataFormat.VARIABLES; 
    loader.addEventListener(Event.COMPLETE, completeHandler); 
    try { 

     loader.load(myRequest); 

    } catch (error:Error) { 

     trace("Unable to load URL"); 
    } 

    function completeHandler(e:Event):void { 

     trace("Data Content:"+e.target.data) 
     trace("Response:"+e.target.data.success); 
    }; 
}; 

sendEmail(); 

php代碼:

<?php 
    $msg = $_POST["msg"]; 
    $to = "[email protected]"; 
    $subject="Message from php"; 
    $success = mail($to,$subject,$msg,"Content-Type: text/plain; charset=utf-8"); 
    echo "temp=1&success=".$success; 
?> 

一切都看起來很簡單,但沒有工作

1)響應:應該是真的還是假的,是:」 $成功; ? >(?壞解析)

2)e.target.data看起來怪怪的:

Data Content:success=%22%20%24success%3B%0D%0A%3F%3E&%3C%3Fphp%0D%0A%09%24msg%20=%20var%5Fexport%28%24%5FPOST%2C%20true%29%3B%0D%0A%09%24to%20%3D%20%22baca%2Erene%40gmail%2Ecom%22%3B%0D%0A%09%24subject%3D%22Message%20from%20php%22%3B%0D%0A%09%24success%20%3D%20mail%28%24to%2C%24subject%2C%24msg%2C%22Content%2DType%3A%20text%2Fplain%3B%20charset%3Dutf%2D8%22%29%3B%0D%0A%09echo%20%22temp%3D1 

3)執行代碼,我沒有收到任何電子郵件....一定出事了之後?

+0

你的網絡服務器有問題(如果你有一個問題),因爲php沒有執行。你應該知道,你不能在沒有Web服務器的情況下運行一個php腳本。 – akmozo

回答

0

爲了:

  1. In PHP Booleans do not echo out "true" or "false" like they do in actionscript-3s trace()。您需要在PHP中使用某種形式的if語句來回顯適當的字符串,而不是直接回顯變量。

  2. e.target.data正在返回一個utf轉義的PHP代碼的字符串版本,這通常表明php沒有執行並且該文件正在被讀作一個字符串,您應該檢查您的服務器配置是否正確並檢查PHP的錯誤日誌(並改變你的php config to write all errors to the log

  3. 是的,有什麼不對,檢查你的PHP配置和錯誤日誌,很可能和SMTP配置錯誤。

你也可以在php中使用error_get_last();來拉出php拋出的最後一個錯誤。

+0

我認爲@Orien試圖執行一個本地的php腳本,甚至沒有一個web服務器。 – akmozo

+0

沒有網絡服務器可能是根本原因,但它沒有提供第一點的解釋(即使使用網絡服務器也不行)或第二點(這是對UTF字符轉義的困惑) – CyanAngel

+0

實際上,他php代碼很好,因爲沒有web服務器來執行它,flash會將其加載爲任何文本文件。回聲PHP布爾值給出1或0. – akmozo