# AS3 - php mail help needed - seems impossible to make

**URL:** <https://forum.kirupa.com/t/as3-php-mail-help-needed-seems-impossible-to-make/291841>\
**Category:** flash\
**Created:** [July 6, 2009, 4:44pm UTC](https://forum.kirupa.com/t/as3-php-mail-help-needed-seems-impossible-to-make/291841 "2009-07-06T16:44:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_paparis](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@john\_paparis](https://forum.kirupa.com/u/john_paparis)\
**Post date:** [July 6, 2009, 4:44pm UTC](https://forum.kirupa.com/t/as3-php-mail-help-needed-seems-impossible-to-make/291841/1 "2009-07-06T16:44:04Z")

</div>

Hi everybody, i have been trying fr some days now to make a simple AS3 - php mail to work. i have read many examples and tried most of them but with no luck. the server i use for testing is capable of sending mail, tried with AS2 many times. can someone please help me ?  
This is the flash code :

var variables:URLVariables=new URLVariables();  
variables.mail=send\_str; ( send\_str is a string i used to coolect info from text fields )

var request:URLRequest=new URLRequest();  
request.url=‘path\_to\_server\_side\_script’; ( mail.php )

request.method=URLRequestMethod.POST;  
request.data=variables;

var loader:URLLoader=new URLLoader();  
loader.dataFormat=URLLoaderDataFormat.VARIABLES;  
loader.addEventListener(Event.COMPLETE,messageSent);  
loader.load(request);

private function messageSent(evt:Event):void {  
var loader:URLLoader=URLLoader(evt.target);  
var vars:URLVariables=new URLVariables(loader.data);  
if (vars.answer==“ok”) {  
/// mail did not go  
} else if (vars.answer==“no”) {  
/// mail delivered  
}  
}

and now for the php script :

\<?php  
$body =$\_POST[‘mail’];  
$subject = "Email from my page \>\>\> ";  
$mailbody = iconv ( ‘UTF-8’, ‘ISO-8859-7’, $body );  
if (mail(‘email\_adress@yahoo.com’, $subject, $mailbody))  
echo “answer=ok”;  
}  
else {  
echo “answer=no”;  
}  
?\>

it produces all kinds of errors, the most common of which that variables should be in name/value pairs. I have tried to replace loader.dataFormat=URLLoaderDataFormat.VARIABLES; with  
loader.dataFormat=URLLoaderDataFormat.TEXT; with no luck.  
Also i tried to start the sending\_str ( the string that i used to collect info from text field ) with var sending\_str:String=“mail=”+name\_txt.text+" "+sirname\_txt.text; in order to have name/value pairs but with no luck.  
if someone understands what is wrong i really need some help with this,  
thanks
