ny-dev | Design & Development Forums  

Go Back   ny-dev | Design & Development Forums > Knowledge Bank > Tutorials

Notices

Reply
 
LinkBack Thread Tools
Old 03-26-2006, 02:47 AM   #1 (permalink)
Senior Member
Addict
 
Cota's Avatar
 
Join Date: Mar 2006
Age: 32
Posts: 450
Cota is a glorious beacon of lightCota is a glorious beacon of light
Default Send an Email with ASP/PHP/Perl

Assuming your flash IDE is open already let’s go ahead and get started. In this tutorial we’ll cover sending emails through flash using a server side script in ASP, PHP, or Perl we will cover all three. With this you can add email functionality to your flash website for endless possibilities. There are a few things to note here. It is a very wise choice to restrict some aspects of this application. Allowing users to decide where the email is going can lead to some serious headaches. By giving users that ability you open yourself to the user using it for anonymous emails, so be careful.

So, with that being said, let’s get started. In Flash, we can do this all in one frame. We’re going to keep it simple. Let’s create 3 input text boxes and 1 dynamic text box. This part is actually important because not using instance names can cause some confusion, so don’t forget instance names. Create the first text box and give it the instance name of “subject_txt”. Next let’s create another text box and call it “email_txt”, again create the 3rd input text box and call it “message_txt”. Make sure you set this text boxes property to multiline. Now create a dynamic text box and call it “status_txt”. Now create a button and give it a name of “submit_btn”.

Now let’s open up the Actions panel and start typing some codes. We’ll be doing a few things here. I won’t be able to explain every detail about everything used because this tutorial would be way too long. We’re simply going to use a flash object called “LoadVars”. We’re also going to surround the whole thing inside an “onRelase” function for the submit button. We will also do some data validation. Also note, there is some extra code, simply for the sake of this tutorial that will allow you to decide whether to use the ASP, PHP, or Perl file. Here’s the code

The Actionscript:
Code:
/* For this tutorial this variable will hold which server-side file you wish to use.
   For ASP, set serverLang = "asp", for PHP, set serverLang = "php"
   And for Perl, set serverlang = "cgi"
   This is for this tutorial. In your application this feature wont be required.
  */
var serverLang:String = "asp";

//Create a loadvars object named email_lv
var email_lv:LoadVars = new LoadVars();

//this function is called when email_lv loads the server-side script.
email_lv.onLoad = function(success) {
    //If the script was successfully loaded, this condition is run
    if (success) {
        /* Though the server-side script was loaded, it does not mean it was 
            executed successfully. This condition gets a response from the
            server-side script and determines if it was truly successful. */
        if (email_lv.server_mes == "ok") {
            status_txt.text = "Email Sent";
            /* You can add additional code here. This is only run
               if everything went as planned. */
        }
    } else {
        //email failed to send, but script did load. Likely a server issue.
        status_txt.text = "Email Failed";
    }
};

/*This is the onRelease function for "submit_btn" button. This is only run
  if the button was pressed. */
submit_btn.onRelease = function() {
    /* Here we are validating the data. This insures the email address contains
       both the "@" and ".", If not, it stops the script and alerts the user. */
    if (!email_txt.length || email_txt.indexOf("@") == -1 || email_txt.indexOf(".") == -1) {
        status_txt.text = "Invalid Email.";
    
    //This validates the subject line contains text
    } else if (!subject_txt.length) {
        status_txt.text = "Missing Subject";
        
    //This validates the message body contains text    
    } else if (!message_txt.length) {
        status_txt.text = "Missing Message";
        
    //If everything is filled out correctly, this is run.    
    } else {
        //Collects the data from the text boxes and gives it to email_lv
        email_lv.email_txt = email_txt.text;
        email_lv.subject_txt = subject_txt.text;
        email_lv.message_txt = message_txt.text;
        
        /* Finally, send the data to the server and get a response. 
           As mentioned above, serverlang holds the file extendion for
           the server side language. You can hard code the complete file name. */
        email_lv.sendAndLoad("SendMail."+serverLang, email_lv, "POST");
    }
};
You can make any required additions to fit your project, but you get the idea. Now let’s move on the ASP code. The SendMail.ASP file uses CDONTs to send the email. Make sure your server supports CDONTS. Here’s the ASP code:
Code:
<%
dim themail, thename, themessage, i

'Gets the incoming variables from flash
themail = Request("email_txt")
thesubject = Request("subject_txt")
themessage = Request("message_txt")

'Decalre and create email object
dim objmail

set objmail = Server.CreateObject("CDONTS.Newmail")
'error handler, if error encountered, ignore it and proceed
On Error resume next

'build the email using the variables from flash
objmail.From = themail
objmail.To = themail
objmail.Subject = thesubject
objmail.Body = themessage
objmail.Send
'error handler, if error encountered, ignore it and proceed
On Error resume next

'If any errors were encounter then run this code
If Err.Number <> 0 then
'tells flash ASP failed and terminates the ASP file.
Response.Write "&server_mes=fail"
Response.End 
else
'Send message back to flash saying everything was ok.
Response.Write "&server_mes=ok"
End if 

%>
Assuming your server supports CDONT’s, then this script should work well. Let’s move on doing the same thing in PHP. Here is the PHP code:
Code:
<?php //tells the server this is php 

//-------------------------------------
// the below code set the headers. There can be a bit difficult to understand fully.
// Information about them and all the commands below can be found at the PHP manual
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Websites Name Here '<' . $_POST['email'] . '>' . "\r\n"; //you can put your website’s name in here or anything else you like
//$headers .= 'Bcc: another@email.com' . "\r\n";   //this is optional.
//------------------------------

// gets variables from flash
$to = your@email.address  //inset the email address it goes to here
$subject = $_POST['subject_txt'];
$message = $_POST['message_txt'];

if ($_POST['message_txt'] != "") { //this checks to make sure someone didn't visit the page manually by making sure message_txt is not empty
    $ok = mail($to, $subject, $message, $headers; //this line sends the mail and returns true or false
    if($ok) {
        echo "&server_mes=ok&"; //if mail was send print to the screen "&server_mes=ok"  
    } else {
        echo "&server_mes=fail&"; // if mail was NOT sent, print to the screen "&server_mes=fail"
    }
}

?>// closes the php session
Ok, one final server side method. For those that for some reason can’t use ASP or PHP you can use Perl. Perl is one of those server side scripts that doesn’t care if you’re using Unix/Linux or Windows, it will run on both. There are 2 Perl files, don’t worry about the “SubParse” file, just focus on the main file, “SendMail.cgi”. Here’s the code:
Code:
#!/usr/local/bin/perl

require "subparse.lib";
&Parse_Form;

$theMail = $formdata{'email_txt'};
$theSubject = $formdata{'subject_txt'};
$theMessage = $formdata{'message_txt'};


open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
print MAIL "To: $theMail \nFrom: $theMail\n";
print MAIL "Subject: $theSubject\n";
print MAIL "$theMessage\n";
close (MAIL);

print "Content-type: text/html\n\n";
Print "&server_mes=ok";

sub ErrorMessage {
print "&server_mes=Fail";
exit; }
So there you have it. Sending mail through flash with 3 methods. Which to use it completely up to you. Modifying the code is fairly easy if you just follow the blue prints that have been laid out for you.
Cota is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 03-27-2006, 02:44 AM   #2 (permalink)
Administrator
Disciple
 
danielmichel's Avatar
 
Join Date: Feb 2003
Age: 29
Posts: 889
Images: 15
danielmichel is a glorious beacon of lightdanielmichel is a glorious beacon of lightdanielmichel is a glorious beacon of light
Send a message via AIM to danielmichel Send a message via MSN to danielmichel Send a message via Yahoo to danielmichel Send a message via Skype™ to danielmichel
Default Re: Send an Email with ASP/PHP/Perl

Thanks for yet another great tutorial Cota.
danielmichel is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 01-02-2007, 11:31 PM   #3 (permalink)
SHP
Sexual Harassment Panda
Aficionado
 
SHP's Avatar
 
Join Date: Dec 2004
Posts: 138
SHP will become famous soon enough
Default Re: Send an Email with ASP/PHP/Perl

You're on Hotscripts
Send an Email with ASP/PHP/Perl
SHP is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 01-03-2007, 09:13 PM   #4 (permalink)
Senior Member
Addict
 
Cota's Avatar
 
Join Date: Mar 2006
Age: 32
Posts: 450
Cota is a glorious beacon of lightCota is a glorious beacon of light
Default Re: Send an Email with ASP/PHP/Perl

its like magic.
__________________
Cota 1, Mods 0....want to go for round 2?
Cota is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 12-30-2008, 05:13 AM   #5 (permalink)
Junior Member
Newb
 
Join Date: Dec 2008
Posts: 13
Jenniferlinn is on a distinguished road
Default Re: Send an Email with ASP/PHP/Perl

Hello Cota

Thanks for sharing script on this forum, I think everybody will gain from it
Jenniferlinn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Old 06-12-2009, 02:35 AM   #6 (permalink)
Junior Member
 
Join Date: Jun 2009
Posts: 3
limonnas is on a distinguished road
Default Re: Send an Email with ASP/PHP/Perl

Download Send an Email with ASP/PHP/Perl Free - Assuming your flash IDE is open already let?s go ahead and get started. In this tutorial we?ll cover sending .
limonnas is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Google Bookmark this Post!Blink this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions about Perl... melissajean85 Software Development 2 12-21-2006 05:29 AM
New Yahoo Worm Exploits email vulnerability chameleon General Conversation 0 06-13-2006 03:41 PM
Form's input to Email Faucet Website Programming 9 05-02-2006 11:56 PM
PHP or Perl? millerl General Conversation 3 03-30-2006 09:51 PM


All times are GMT -4. The time now is 04:32 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
347media

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24