JavaScript
  Home arrow JavaScript arrow Page 3 - Sending Email with an SMTP Client Built wi...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Sending Email with an SMTP Client Built with Prototype and PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-10-02

    Table of Contents:
  • Sending Email with an SMTP Client Built with Prototype and PHP
  • The complete client-side code of the SMTP application
  • Sending email with PHP
  • Full source code of the SMTP client application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sending Email with an SMTP Client Built with Prototype and PHP - Sending email with PHP


    (Page 3 of 4 )

    In accordance with the concepts that I deployed in the previous section, I'm going build a short PHP script which will be tasked with receiving the email data inputted by the user via the corresponding front-end, and then sending out the email message to the specified recipients.

    As you can see, the logic that stands behind this PHP snippet sounds really easy to grasp, but you'll find it even simpler if you take a look at its signature, which is listed below:

    <?php

     // clean up GET data

      array_map('trim',$_GET);

     // check if 'to' field has been filled or not

       if(!$_GET['to']){

        echo 'STATUS: PLEASE SPECIFY AN EMAIL ADDRESS';

      exit();

     }

     // check if 'subject' field has been filled or not

       if(!$_GET['subject']){

        echo 'STATUS: PLEASE SPECIFY A SUBJECT';

      exit();

     }

     // check if 'message' field has been filled or not

       if(!$_GET['message']){

        echo 'STATUS: PLEASE ENTER YOUR MESSAGE';

      exit();

     }

     // get message fields

      $to=$_GET['to'];

       $subject=$_GET['subject'];

       $message=$_GET['message'];

     // define MIME headers

      $headers="MIME-Version 1.0rn"."Content-Type: text/plain;
    charset=iso-8859-1rn"."From: myaddress@mydomain.comrn"."Reply-to:
    myaddress@mydomain.comrn";

     // check if 'Cc' field has been filled or not

       if(!empty($_GET['cc'])){

        $headers.="Cc: ".$_GET['cc']."rn";

     }

     // check if 'Bcc' field has been filled or not

       if(!empty($_GET['bcc'])){

        $headers.="Bcc: ".$_GET['bcc']."rn";

     }

     // send email

       if(!@mail($to,$subject,$message,$headers)){

        echo 'STATUS: ERROR SENDING MESSAGE';

      exit();

     }

      else{

       echo 'STATUS: MESSAGE WAS SENT SUCCESSFULLY';

     exit();

     }

    ?>

    As illustrated above, the PHP script responsible for sending out email messages is in fact quite simple to follow. It begins by checking some required parameters, such as the email address of the recipient to which the message will be submitted, and the subject and text of the message as well.

    After performing these crucial verification tasks, the script finally determines if any values have been specified for the respective carbon copies and blind carbon copies, and finally sends the email message by using the intuitive "mail()" PHP native function. In addition, in all cases, different status messages are displayed in the client according to the different data checking processes performed in the server.

    Okay, at this point hopefully you'll have a pretty accurate idea of how this SMTP client works, since its respective client and server-side modules are indeed simple to understand. Thus, in the last section of this tutorial, I'm going to list the complete source code that corresponds to this email application, this time including the short PHP script that you learned before.

    To see how this will be achieved, go ahead and read the next few lines.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this concrete article of the series, the PHP script that actually sends email to...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek