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 / 23
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

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

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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