Amina
Points:260
Posts:11
3/10/2010 7:05:16 AM
Title:
sending mail
hello everybody
I am trying to develop sending mail within an application flex builder 3
So here is my php code
<!--
<?php
$senderName = $_POST['senderName'];
$senderEmail = $_POST['senderEmail'];
$sendToName = $_POST['sendToName'];
$sendToEmail = $_POST['sendToEmail'];
$emailMessage = $_POST['emailMessage'];
$recipient = "$sendToEmail";
$subject = "Hi there";
$headers = "From: $senderEmail ";
$message = "From: $senderName\nEmail Address: $senderEmail\nTo: $sendToName\nEmail Address: $sendToEmail\n\nMessage: $emailMessage";
$message = StripSlashes($message);
mail($recipient, $subject, $message, $headers)
?>
-->
and here is my code Felx
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent ;
public function sendEmail():void
{
var senderName:String = senderName.text;
var senderEmail:String = senderEmail.text;
var sendToName:String = sendToName.text;
var sendToEmail:String = sendToEmail.text;
var emailMessage:String = emailMessage.text;
this.emailService.send({senderName: senderName, senderEmail:senderEmail, sendToName: sendToName, sendToEmail: sendToEmail, emailMessage: emailMessage});
if (cb.selected == true)
{
this.emailService.send({senderName: senderName, senderEmail:senderEmail, sendToName: sendToName, sendToEmail: senderEmail, emailMessage: emailMessage});
}
}
public function emailResult():void
{
Alert.show("Email Has Been Sent");
}
]]>
</mx:Script>
<mx:HTTPService id="emailService" url="./css/php/email.php" method="POST" resultFormat="xml" result="emailResult()" useProxy="false"/>
<mx:Panel width="510" height="449" >
<mx:Text width="100%" height="29" text="Simple Email Form" styleName="header" fontWeight="bold"/>
<mx:HRule width="100%"/>
<mx:Form id="emailForm" width="100%" >
<mx:FormItem label="Your Name:" horizontalAlign="left" width="100%" fontWeight="bold">
<mx:TextInput id="senderName" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Your E-mail:" width="100%" fontWeight="bold">
<mx:TextInput id="senderEmail" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Friends Name:" horizontalAlign="left" width="100%" fontWeight="bold">
<mx:TextInput id="sendToName" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Friends E-mail:" width="100%" fontWeight="bold">
<mx:TextInput id="sendToEmail" width="100%"/>
</mx:FormItem>
<mx:FormItem label="Message" horizontalAlign="left" width="100%" fontWeight="bold">
<mx:TextArea id="emailMessage" width="100%" height="100"/>
</mx:FormItem>
<mx:FormItem width="100%" height="35">
<mx:Spacer width="200" />
<mx:Button id="submitBtn" label="Submit" click="this.sendEmail();"/>
</mx:FormItem>
</mx:Form>
<mx:HRule width="100%"/>
</mx:Panel>
</mx:Application>
the problem is, there is no bug and no sending mail !!!!!!!!!!
3/10/2010 9:44:29 AM
your code seems fine.
have you tested your php page by hard coding the values. there might be email server prob.
Just test your php page first by calling it in browser not by flex.
3/10/2010 10:42:52 AM
to test your email server , run this php code .
open notepad paste this code, modify your email address to send mail and also from address and save as testmail.php
upload to your server and open url
http://yourdomain.com/testmail.php
it should send mail , see if it works .
<?php
mail("toyouremail@youremail.com", " Test subject"," Test message", "fromyouremail@yourdomain.com");
echo " test email sent";
?>
Amina
Points: 260
Posts:11
3/10/2010 1:28:20 PM
hello and thank you for answers
I come back after my tests
Amina
Points: 260
Posts:11
3/10/2010 1:47:14 PM
hi!still me.
knowing that I work locally so in my HTTPService:
////////////
<mx:HTTPService id="emailService" url="http://localhost/testmail.php "method="POST" resultFormat="xml" result="emailResult()" useProxy="false"/>
///////////////////
and here is the error that sent me flex
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Erreur de flux. URL: http://localhost/testmail.php"]. URL: http://localhost/testmail.php "]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at DirectHTTPMessageResponder/errorHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:362]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/redirectEvent()
3/10/2010 3:28:31 PM
is your email server setup properly,
check your page path by entering this path in your browser
http://localhost/testmail.php
after opening page see if it sends mail.
the above error is IO error which means the page is not available or accessible .
place your swf file and php file in same directory to avoid security error.I mean to say the swf should be also inside localhost directory.
3/10/2010 10:10:20 PM
Hi amina , I have found your bug. On running your php page i got error regarding some line ending format wrong. To fix it replace all your newline \n with \r\n in message body like this :
$message = "From: $senderName\r\nEmail Address: $senderEmail\r\nTo: $sendToName\r\nEmail Address: $sendToEmail\r\n\r\nMessage: $emailMessage \r\n";
In your flex code there was error for "cb.selected" so I removed the condition.
I have tested your flex code with your php code after fixing and it works like charm.
Amina
Points: 260
Posts:11
3/11/2010 12:10:34 PM
hi
oh thank you dave is very nice of you :D
and of course thank you to all who helped me in this super cool forum