PEAR Articles

  Home arrow PEAR Articles arrow Page 5 - Installing a PEAR Package
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!

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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.
    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - 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


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap