Home arrow HTML arrow Page 3 - Sending Email with AJAX: Interacting with the Server
HTML

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.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 16
January 31, 2006
TABLE OF CONTENTS:
  1. · Sending Email with AJAX: Interacting with the Server
  2. · Sending email with PHP: developing a straightforward script
  3. · Getting the server-side application layer completed: listing the “addcontact.php” PHP file
  4. · Putting the layers together: listing the application’s source code, first section
  5. · Listing the application's source code, second section

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials