PEAR Articles
  Home arrow PEAR Articles arrow Page 4 - 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 - Mail Package


    (Page 4 of 5 )


    The last package that we will install and look at is the Mail package. This package is used to send email from PHP. I’ve written a small HTML form that will take information such as the message body, subject and recipient email address. Below is the code:

    <?php

    //is form submitted

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

    require "Mail.php";

    //collect the information

    $from=$email;

    $cc=$_POST['cc'];

    $bcc=$_POST['bcc'];

    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'];

    }

    //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”;

    }



    if(!$error){

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

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

    }

    if(!$res){

    echo "Mail error occurred";

    }

    }


    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Untitled Document</title>

    </head>


    <body>

    <span class="style2">Sending Mail With PHP</span>

    <form name="form1" method="post" action="untitled2.php">

    <table width="100%" border="0" class="block">

    <tr>

    <td width="10%" valign="top"><strong>To</strong></td>

    <td width="90%"><input name="tos" type="text" id="to" size="70" value="david@web.com"/></td>

    </tr>

    <tr>

    <td valign="top"><strong>Cc</strong></td>

    <td><input name="cc" type="text" id="cc" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Bcc</strong></td>

    <td><input name="bcc" type="text" id="bcc" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Subject</strong></td>

    <td><input name="sub" type="text" id="sub" size="70" />

    <input type="hidden" name="hkey" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Attachment</strong></td>

    <td>

    <input name="userfile" type="file" id="userfile" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Message:</strong></td>

    <td><label>

    <textarea name="msg" cols="50" rows="10"></textarea>

    </label></td>

    </tr>

    <tr>

    <td>&nbsp;</td>

    <td><input type="submit" name="submit" value="Send Message" />

    </td>

    </tr>

    </table>

    </form>

    </body>

    </html>


    The HTML form collects the various bits of information such as the body of the message, the subject and the recipient address, that are required by the mail class. It also takes attachments as indicated below:

    <table width="100%" border="0" class="block">

    <tr>

    <td width="10%" valign="top"><strong>To</strong></td>

    <td width="90%"><input name="tos" type="text" id="to" size="70" value="david@web.com"/></td>

    </tr>

    <tr>

    <td valign="top"><strong>Cc</strong></td>

    <td><input name="cc" type="text" id="cc" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Bcc</strong></td>

    <td><input name="bcc" type="text" id="bcc" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Subject</strong></td>

    <td><input name="sub" type="text" id="sub" size="70" />

    <input type="hidden" name="hkey" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Attachment</strong></td>

    <td>

    <input name="userfile" type="file" id="userfile" size="70" /></td>

    </tr>

    <tr>

    <td valign="top"><strong>Message:</strong></td>

    <td><label>

    <textarea name="msg" cols="50" rows="10"></textarea>

    </label></td>

    </tr>

    More PEAR Articles Articles
    More By David Web


       · 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 2 Hosted by Hostway
    Stay green...Green IT