Sending Email with AJAX: Interacting with the Server
Here we are again. Welcome to the last tutorial of the series “Sending email with AJAX.” As you may have guessed regarding the title, this three-part series explains the development of a fairly simple AJAX-driven email client application, which offers some interesting capabilities for sending email, as well as for displaying and adding contacts, all without the need to involve page reloads.
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:
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.