HTML
  Home arrow HTML arrow Page 3 - Sending Email with AJAX: Interacting with ...
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 
Sun Developer Network 
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? 
HTML

Sending Email with AJAX: Interacting with the Server
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 12
    2006-01-31

    Table of Contents:
  • Sending Email with AJAX: Interacting with the Server
  • Sending email with PHP: developing a straightforward script
  • Getting the server-side application layer completed: listing the “addcontact.php” PHP file
  • Putting the layers together: listing the application’s source code, first section
  • Listing the application's source code, second section

  • 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 AJAX: Interacting with the Server - Getting the server-side application layer completed: listing the “addcontact.php” PHP file


    (Page 3 of 5 )

    As I previously explained, below is the source code list that corresponds to the “addcontact.php” PHP file, which as you’ll probably recall, is tasked with inserting new nodes into the XML file that stores contact data:

    $file='contacts.xml';
    array_map('trim',$_POST);
    $str='<contact>'."\n".'<name>'.$_POST
    ['fullname'].'</name>'."\n".'<email>'.$_POST
    ['email'].'</email>'."\n".'</contact>'."\n".'</contactlist>';
    if(!$fp=fopen($file,'r+')){
      trigger_error('Error opening contacts file',E_USER_ERROR);
    }
    $contents=fread($fp,filesize($file));
    rewind($fp);
    $contents=str_replace('</contactlist>',$str,$contents);
    //header('Content-Type: text/xml');
    fwrite($fp,$contents);
    fclose($fp);

    Is the above PHP script now fresh in your mind? I hope so. Now, let’s complete the server-side application layer, by showing how a sample XML contact file would look:

    <?xml version="1.0" encoding="iso-8859-1"?>
    <contactlist>
    <contact>
    <name>Full Name 1</name>
    <email>address1@domain1.com</email>
    </contact>
    <contact>
    <name> Full Name 2</name>
    <email> address2@domain2.com </email>
    </contact>
    <contact>
    <name> Full Name 3</name>
    <email> address3@domain3.com </email>
    </contact>
    <contact>
    <name> Full Name 4</name>
    <email> address4@domain4.com </email>
    </contact>
    <contact>
    <name> Full Name 5</name>
    <email> address5@domain5.com </email>
    </contact>
    </contactlist>

    All right, at this stage, I think I’ve finished defining the building blocks that comprise the complete server-side layer of my AJAX email application. As you’ve seen, a couple of extendable PHP snippets are all I need to get the program interacting in a seamless way with the server. This should demonstrate that building up this kind of applications isn’t difficult at all.

    However, this AJAX-driven email application wouldn’t be complete without listing together both client and server-side layers, which can be quite useful if you want to have the entire source code available in one place. Keeping this in mind, jump into the last two sections of this article, in order to see how the complete AJAX-driven program looks.

    More HTML Articles
    More By Alejandro Gervasio


       · Having developed the client-side application layer of this AJAX-based email program...
     

    HTML ARTICLES

    - Using a 3D HTML Table as a Recordset
    - Building a 3D HTML Table
    - Maximizing and Restoring HTML Images: Layer ...
    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT