PHP CLASS to send email with attachments

Discussion in 'PHP' started by astkboy2008, Jan 14, 2010.

  1. #1
    every one know how to send an email by php but no many people now how we attach file in the email.
    today i get php class to do that job
    This is a class that can send all sorts of email. Plain text, HTML (with or without images), attachments etc. First written in 2000, it's very mature and is in use by lots of major websites. Updated for PHP5, it takes advantage of PHP5 features to be very efficient at sending all sorts of email.
    User contributions

    The namedFileAttachment.php (from Peter Van Valderen) file allows you to specify a different file name for an attachment if you wish.

    examples
    example.php
    
    <?php
        /**
        * o------------------------------------------------------------------------------o
        * | This package is licensed under the Phpguru license. A quick summary is       |
        * | that for commercial use, there is a small one-time licensing fee to pay. For |
        * | registered charities and educational institutes there is a reduced license   |
        * | fee available. You can read more  at:                                        |
        * |                                                                              |
        * |                  http://www.phpguru.org/static/license.html                  |
        * o------------------------------------------------------------------------------o
        *
        * © Copyright 2008,2009 Richard Heyes
        */
    
        require_once('Rmail.php');
        
        $mail = new Rmail();
    
        /**
        * Set the from address of the email
        */
        $mail->setFrom('Richard <richard@example.com>');
        
        /**
        * Set the subject of the email
        */
        $mail->setSubject('Test email');
        
        /**
        * Set high priority for the email. This can also be:
        * high/normal/low/1/3/5
        */
        $mail->setPriority('high');
    
        /**
        * Set the text of the Email
        */
        $mail->setText('Sample text');
        
        /**
        * Set the HTML of the email. Any embedded images will be automatically found as long as you have
    added them
        * using addEmbeddedImage() as below.
        */
        $mail->setHTML('<b>Sample HTML</b> <img src="background.gif">');
        
        /**
        * Set the delivery receipt of the email. This should be an email address that the receipt should
    be sent to.
        * You are NOT guaranteed to receive this receipt - it is dependent on the receiver.
        */
        $mail->setReceipt('test@test.com');
        
        /**
        * Add an embedded image. The path is the file path to the image.
        */
        $mail->addEmbeddedImage(new fileEmbeddedImage('background.gif'));
        
        /**
        * Add an attachment to the email.
        */
        $mail->addAttachment(new fileAttachment('example.zip'));
    
        /**
        * Send the email. Pass the method an array of recipients.
        */
        $address = 'fruity@licious.com';
        $result  = $mail->send(array($address));
    ?>
    
    Email has been sent to <?=$address?>. Result: <?var_dump($result)?>
    PHP:
    download:Rmail.1.0.zip [23 KB]
    see other examples:


    see the pack files

     
    astkboy2008, Jan 14, 2010 IP
  2. snnyk

    snnyk Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    thanks all :)
     
    snnyk, Jan 14, 2010 IP
  3. maryjoanna

    maryjoanna Peon

    Messages:
    287
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that is very nice thanks!
     
    maryjoanna, Jan 14, 2010 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not available for commercial use though without charge. PHPMailer is by far superior
     
    JAY6390, Jan 14, 2010 IP
  5. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for information
     
    astkboy2008, Jan 16, 2010 IP
  6. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    whar is that mr.henrinaiara you should make this topic not sperated posts
     
    astkboy2008, Jan 16, 2010 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you hadn't noticed he's spamming the link
     
    JAY6390, Jan 16, 2010 IP
  8. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Ohh thanks frined..., from long time i am looking for this concept
     
    strgraphics, Jan 16, 2010 IP
  9. astkboy2008

    astkboy2008 Peon

    Messages:
    211
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks for you strgraphics
     
    astkboy2008, Jan 27, 2010 IP
  10. SIAWebDesign

    SIAWebDesign Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Thanks a lot guys, this is very helpful :) I looked every where for a way to attach background to my emails.
     
    SIAWebDesign, Feb 8, 2010 IP