PEAR Articles
  Home arrow PEAR Articles arrow Page 5 - Installing a PEAR Package
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
PEAR ARTICLES

Installing a PEAR Package
By: David Web
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-09-24

    Table of Contents:
  • Installing a PEAR Package
  • Using the installed Packages
  • mdb2 Package
  • Mail Package
  • More Mail!

  • 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


    Installing a PEAR Package - More Mail!


    (Page 5 of 5 )


    Once the user clicks on the “Send Message” button, the PHP code at the top of the page checks to see if the form has been submitted. If so, it immediately requires the mail class:

    <?php

    //is form submitted

    if(isset($_POST['key'])){

    require "Mail.php";

    Then it checks to see that all the required information is included in the submitted form. Remember that the mail() function requires three pieces of information, the subject, body and recipient address. So it is important that we ensure that those values are there:

    //collect the information

    $from=$email;

    $cc=$_POST['cc'];

    $bcc=$_POST['bcc'];

    The empty() function that is provided by PHP is used to check whether or not the form variables contain any values. If the form variables are empty, a error message is set up stating so:

    if(empty($_POST['tos'])){

    $error=true;

    }else{

    $to=$_POST['tos'];

    }

    if(empty($_POST['sub'])){

    $error=true;

    }else{

    $subject=$_POST['sub'];

    }

    if(empty($_POST['msg'])){

    $error=true;

    }else{

    $msg=$_POST['msg'];

    }

    The next code checks to see if the user included a attachment. You probably noticed a browse button on the HTML form that allows the user to search for a file on the local system for attachment to the mail message. The logic for this check works like so: it first checks to see if the user included an attachment by searching the FILE array. If a file is found, it is first stored in a variable called filename, and then it is attached to the headers section of the Mail message:

    //check if the an attachment is present

    if(isset($_FILES['userfile']['name'])){

    $attachment = $_FILES['userfile']['tmp_name'], $_FILES['userfile']['name'];

    $headers =“Content-disposition: attachment;

    $filename=.$attachment."n";

    $headers=.Content-Transfer-Encoding: base64n”;

    }

    Finally, if no errors occurred in the script, we send the message using the mail class’s factory method: 

    if(!$error){

    $mail = Mail::factory('mail');

    $mail->send($to, $headers, $msg);

    }

    If there is an error in sending the message, the appropriate message is printed out:

    if(!$res){

    echo "Mail error occurred";

    }

    }


    ?>

    To uninstall these packages, you simply type the following at the command prompt:

    pear uninstall packagename

    If the package that you are using has been updated, you simply type:

    pear upgrade packagename

    In the next article we will start to build a complete Content Management System using PEAR::DB.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · I have a question regarding PEAR,As a PHP Web Developer I am accustomed to...
     

    PEAR ARTICLES ARTICLES

    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning
    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT