Example: Sending Email Using a Remote PHP Web Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Corey
    Indigo Rose Staff Alumni
    • Aug 2002
    • 9745

    Example: Sending Email Using a Remote PHP Web Script

    You can easily submit values to online scripts using AutoPlay Media Studio. In this example we will build a PHP script to send email, and then setup an AutoPlay Media Studio application to interact with it. The result will be an AutoPlay Media Studio application which can send your information by email. It's easy to do and only takes 3 simple steps.

    STEP 1 : CREATE AND UPLOAD YOUR PHP SCRIPT
    -----------------------------------------------


    Using any text editor (such as notepad) create a blank text file and type the following into the blank document:

    PHP Code:
    <?php

    // specify recipient email address
    $to="TYPE-YOUR-EMAIL-ADDRESS-HERE";

    // send our email
    mail ("$to","$subject","$body","$from");

    ?>
    Once you have that done, save the document as "mail.php" and upload it to any web server which has PHP installed. if you aren't sure if your web site supports PHP contact your sysadmin for details. If you need a reliable host, the $9/month "4U shared hosting account" at http://www.tera-byte.com is a great value and offers full support for PHP. Once you have mail.php uploaded it's time for step 2.

    STEP 2: SETUP YOUR AUTOPLAY MEDIA STUDIO PROJECT
    -----------------------------------------------


    Either use the attached project or create a blank one. You'll need input fields for your return email address, email subject, and email message. As well you will need a button. The button will contain all the actions for the project. In the attached example I also put in a title and labels so users will know which fields to type into, etc. Once you have your page laid out, you're ready for the final step, adding the code.

    STEP 3: ADDING OUR BUTTON CODE
    -----------------------------------------------


    In this step we add actions to the buttons onClick event. The actions are as follows:

    Code:
    -- clear error variable
    error = 0;
    
    -- Get values from input fields
    from = Input.GetText("Input1");
    subject = Input.GetText("Input2");
    body = Input.GetText("Input3");
    
    -- check for empty fields and deliver errors if needed
    if String.Length(from) < 1 then
    Dialog.Message("Error", "Please enter your email address and re-submit. Thank you.");
    error = 1;
    end
    if String.Length(subject) < 1 then
    Dialog.Message("Error", "Please enter your email subject and re-submit. Thank you.");
    error = 1;
    end
    if String.Length(body) < 1 then
    Dialog.Message("Error", "Please enter your email message and re-submit. Thank you.");
    error = 1;
    end
    
    if error~=1 then
    -- if no errors exist, send the email now and give a confirmation dialog
    HTTP.Submit("http://www.yourwebsite.com/mail.php", {from=from, subject=subject, body=body}, SUBMITWEB_POST, 20, 80, nil, nil);
    Dialog.Message("Success", "Success, your info has been submitted.");
    Application.Exit();
    end
    As you can see we first gather the data from the input fields, then we check for "empty field" errors. And in the final step, if there are no errors, we submit the data to our mail.php script from step one. Remember to adjust the action in the attached example if you are using it, to match the web site address where you uploaded your mail.php script.

    Well, that's it. Hope this was useful. It's just a simple example. You can easily augment this to return values from the server or mail.php if you like, check out the help file entry for the HTTP.Submit action for details. If you have any questions, just let me know and I'll be happy to assist.

    Corey Milner
    Creative Director : Indigo Rose Software
    Attached Files
  • sside
    New Member
    • Dec 2003
    • 475

    #2
    Hello Corey

    I'm a php beginer so any php script it is very appreciated.
    I just tried your script, very simple, very powerful. In my occassion works perfect. But how would it be if using a web object. I tried to adopt your code in a web object, but nowhere...
    Would you like to make a little example using a web object. It would be very appreciated.

    Thank you

    sside

    Comment

    • sside
      New Member
      • Dec 2003
      • 475

      #3
      I've got it. It works now as a web object.

      sside

      Comment

      • Intrigued
        Indigo Rose Customer
        • Dec 2003
        • 6138

        #4
        Now this simple PHP code is crystal clear!

        I recommend that anyone who takes time to learn a new programming language come back and search these forums for posts that relate to said programming language.

        It's like finally closing a circle!
        Intrigued

        Comment

        • Corey
          Indigo Rose Staff Alumni
          • Aug 2002
          • 9745

          #5
          Cool beans I-man. Glad to hear you have discovered how easy it is to use PHP. I started using PHP in version 2.0 and although I never really became an "expert" per se, it's always gotten me everywhere I needed to go. It's a great language with a great future. :yes

          Comment

          • Brett
            Indigo Rose Staff Member
            • Jan 2000
            • 2001

            #6
            I agree. AMS and PHP are a fantastic cobination. On friday I made an internal IR utility program with AMS that POSTS to a PHP page which does some work and returns the answer. It would have taken at leats 10x longer to do in C/C++. Using AMS50 and PHP you have a combination that can rival the power of many heavy frameworks like .NET for making simple client-server applications.

            Comment

            • Intrigued
              Indigo Rose Customer
              • Dec 2003
              • 6138

              #7
              Originally posted by Brett
              I agree. AMS and PHP are a fantastic cobination. On friday I made an internal IR utility program with AMS that POSTS to a PHP page which does some work and returns the answer. It would have taken at leats 10x longer to do in C/C++. Using AMS50 and PHP you have a combination that can rival the power of many heavy frameworks like .NET for making simple client-server applications.
              Oh, and without all that dependency baggage (READ: Heavy)! Oh, that .NET framework, grrr.

              What, with PHP 5, it's like adding (well, at least for Web Applications) 2,700+ more functions!

              Finally, I like that the syntax of Flash MX 2004, PHP 5, and LUA (AMS 5) are not all that syntactically different! It is making the learning curve that more easy to grasp and just as important, easier to remember such various code syntaxes.

              Talk about a one-two(-three) punch!

              Incidently, here is how I learned the setcookie() six (6) arguments, FWIW:

              N. - Name
              V. - Value
              E. - Expiration
              P. - Path
              D. - Domain
              S. - Secure
              Last edited by Intrigued; 03-20-2005, 10:06 AM.
              Intrigued

              Comment

              • Intrigued
                Indigo Rose Customer
                • Dec 2003
                • 6138

                #8
                I just did my first fwrite().

                *clinches hand into a fist and lowers it to his side, then violently reels his fist back to his waste repeatedly... in a sign of success!*

                :yes (Time to get a fish dinner)
                Intrigued

                Comment

                • Corey
                  Indigo Rose Staff Alumni
                  • Aug 2002
                  • 9745

                  #9
                  Flash MX 2004, PHP 5, and LUA (AMS 5)
                  Yep, to some extent there is great similarity. PHP was based upon C whereas Flash actionscript is based upon the Javascript DOM. I'm not sure but I believe Lua is based on C too, or at least I've read it was written in ANSI C. Anyhow there's some fundamental differences between PHP and Javascript/actionscript of course, but for the most part the same concepts apply, i.e. concatenation, operators, functions, etc. Once you know your way around a script, it's just a matter of syntax to achieve the same thing on a different platform.

                  That's why I try to emphasise the raw planning stage in design, so your designs become completely independent of platform limitations. *So* often in this industry the technology is driven by the limits of the tools, but I've never subscribed to that. As far as I'm concerned the game is forcing the tools to meet the task, not the other way around.

                  Comment

                  • Intrigued
                    Indigo Rose Customer
                    • Dec 2003
                    • 6138

                    #10
                    I thought this book would take six (6) weeks to read (I make lots of notes in my books). It's day five (5) and I am two-thirds the way through it. It's just easy going. I'm glad I did not wait any longer to get on the PHP bandwagon! I'm getting ready to use SQLite outside of AMS 5 (in a project). Now, I just need to get the hosting company to upgrade to PHP 5! (I called, hopefully soon)
                    Intrigued

                    Comment

                    • Corey
                      Indigo Rose Staff Alumni
                      • Aug 2002
                      • 9745

                      #11
                      FWIW MySQL is a much better solution for remote DB than SQLite at this point in time, and MySQL is super easy to run and manage from PHP. the relationship between MySQL and PHP is highly transparent. There's a few free hosts out there who offer PHP5 and MySQL, if you just need an account to practice. FWIW in the meantime PHP4 is totally sufficient for getting pretty much anything you need to do, i.e. everything we have online is fully compatible with PHP4.

                      Comment

                      • Intrigued
                        Indigo Rose Customer
                        • Dec 2003
                        • 6138

                        #12
                        Originally posted by Corey
                        FWIW MySQL is a much better solution for remote DB than SQLite at this point in time, and MySQL is super easy to run and manage from PHP. the relationship between MySQL and PHP is highly transparent. There's a few free hosts out there who offer PHP5 and MySQL, if you just need an account to practice. FWIW in the meantime PHP4 is totally sufficient for getting pretty much anything you need to do, i.e. everything we have online is fully compatible with PHP4.
                        I use the 1and1.com account that Brett told us about. It has PHP and you can setup a database. I'll have to check... it may be MySQL too.

                        I'll check into it here in a bit, thanks. :yes

                        [Just did] Good news too!

                        MySQL Database Set Up and Configuration

                        This rocks! Three years of this pro package for free! Brett did good by us for sharing that offer way back, last year!
                        Last edited by Intrigued; 03-20-2005, 05:04 PM.
                        Intrigued

                        Comment

                        • Corey
                          Indigo Rose Staff Alumni
                          • Aug 2002
                          • 9745

                          #13
                          Yeah, Brett's a peach. MySQL rules!!! :yes

                          Comment

                          • Intrigued
                            Indigo Rose Customer
                            • Dec 2003
                            • 6138

                            #14
                            Here's a screen capture of the Web Application control panel for instance:
                            Attached Files
                            Intrigued

                            Comment

                            • Corey
                              Indigo Rose Staff Alumni
                              • Aug 2002
                              • 9745

                              #15
                              Not bad for free. :yes

                              Comment

                              Working...
                              X