Activity Stream
48,167 MEMBERS
61127 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 10 of 10
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default [PHP] E-mailer (Attachment Support) [/PHP]

    Heres a nice email class i createed that you can use in your projects and you can also add attachments to the email....

    Key-Features:
    • Simple OOP
    • Plain-Text OR Html Formatted
    • Use both Plain-Text and Html to help with unsupported clients
    • Able to add attachments of any sort
    • Based on PHP-Mail
    • Multiple Recipients in one batch
    • Built for "Php Newbies"


    Available on PhpClasses

    Some Usage Smaples

    Simple Plain text
    PHP Code: 
    <?php

    //Include the emailer class
    include 'Emailer.class.php';

    //Load the Emailer class into a variable
    $Emailer = new Emailer;

    //Setup where and where from the message is being sent.
    $Emailer->set_to("some_email@some_domain.tld");
    $Emailer->set_from("admin@localhost");
    $Emailer->set_sender("me@domain.com");

    //Afdd some message stuff
    $Emailer->set_subject("This is a plain-text email");
    $Emailer->set_text("Hello World!");

    $Emailer->send();
    ?>
    HTML formatted with
    PHP Code: 
    <?php

    //Include the emailer class

    include 'Emailer.class.php';

    //Load the Emailer class into a variable
    $Emailer = new Emailer;

    //Setup where and where from the message is being sent.
    $Emailer->set_to("some_email@some_domain.tld");
    $Emailer->set_from("admin@localhost");
    $Emailer->set_sender("me@domain.com");

    //Add some message stuff
    $Emailer->set_subject("This is a html formatted email");

    /*Set the text if the end-user does not have the correct software to view html*/
    $Emailer->set_text("Hello World! (Non html version)");
    $Emailer->set_html("<strong>Hello World!</strong> (html Version)");

    //html will show if supported otherwise they will be sent a nice plain-text version

    $Emailer->send();
    ?>
    HTML Formatted with Attachments
    PHP Code: 
    <?php

    //Include the emailer class

    include 'Emailer.class.php';

    //Load the Emailer class into a variable
    $Emailer = new Emailer;

    //Setup where and where from the message is being sent.
    $Emailer->set_to("some_email@some_domain.tld");
    $Emailer->set_from("admin@localhost");
    $Emailer->set_sender("me@domain.com");

    //Afdd some message percifics
    $Emailer->set_subject("This is a html formatted email with files");

    /*Set the text if the end-user does not have the correct software to view html*/
    $Emailer->set_html("Here's your files");

    //Add some files
    $Emailer->add_attachments(
        array(
          
    "test/account_details.txt",
          
    "test/your_avater.png",
          
    "test/some_sample_source.php",
          
    "test/some_random.ext"
          
    /*Add as many as you wish but try not overload the message size by sending 100MB download lol*/
        
    )
    );

    $Emailer->send();
    ?>
    I Hope you like this and heres the actual class file

    PHP Code: 
    <?php
    class Emailer{
        
        
    /*protected Methods*/
        
    protected
            
    $to,
            
    $from,
            
    $sender,
            
    $subject,
            
    $text,
            
    $html;
            
        
    /*Attachments Holder*/
        
    protected $attachments = array();
        
        
    /*Public Variables*/
        
    public $charset 'utf-8';
        public 
    $eol "\r\n";
        
        
    /*Constructor*/
        
    public function __construct(){
            
    /*null*/
        
    }
        
        
    //Setters
        
    public function set_to($to){$this->to $to;}
        public function 
    set_from($from){$this->from $from;}
        public function 
    set_sender($sender){$this->sender $sender;}
          public function 
    set_subject($subject){$this->subject $subject;}
        public function 
    set_text($text){$this->text $text;}
          public function 
    set_html($html){$this->html $html;}
        
        
    //Adders
        
    public function add_attachments($attachment){
            
    //Check if input is an array or string
            
    if(!is_array($attachment)){$attachment = array($attachment);}
            
    $this->attachments array_merge($this->attachments$attachment);
        }
        
        
    //Send mail
        
    public function send(){
            
    //Check Variables are set
            
    if(empty($this->to)){
                
    trigger_error('To required (Use set_to() to set this)!',E_USER_ERROR);
            }
            if(empty(
    $this->from)) {
                
    trigger_error('From required! (Use set_from() to set this)',E_USER_ERROR);
            }
            if(empty(
    $this->sender)){
                
    trigger_error('Sender required! (Use set_sender() to set this)',E_USER_ERROR);
            }
            if(empty(
    $this->subject)){
                
    trigger_error('Subject required! (Use set_subject() to set this)',E_USER_ERROR);
            }
            if((empty(
    $this->text)) && (empty($this->html))){
                
    trigger_error('Message required! (Use set_text() OR set_html() to fix this)',E_USER_ERROR);
            }
            
            
    //Check for multiple emails within the the send to var.
            
    $this->to = (is_array($this->to) ? implode(','$this->to) : $this->to);
            
            
    //Start compiling the email
            
    $this->boundary '----=_NextPart_' md5(rand());
            
    $this->headers '';
            
    $this->message '';
            
            
    //Do top headers
            
    $this->headers .= 'From: ' $this->sender '<' $this->from '>' $this->eol;
            
    $this->headers .= 'Reply-To: ' $this->sender '<' $this->from '>' $this->eol;
            
    $this->headers .= 'Return-Path: ' $this->from $this->eol;
            
    $this->headers .= 'X-Mailer: PHP/' phpversion() . $this->eol;
            
    $this->headers .= 'MIME-Version: 1.0' $this->eol;
            
    $this->headers .= 'Content-Type: multipart/mixed; boundary="' $this->boundary '"' $this->eol;
            
            if(empty(
    $this->html)){
                
    //Text Only
                
    $this->message  '--' $this->boundary $this->eol;  
                
    $this->message .= 'Content-Type: text/plain; charset="' $this->charset '"' $this->eol
                
    $this->message .= 'Content-Transfer-Encoding: base64' $this->eol $this->eol;
                
    $this->message .= chunk_split(base64_encode($this->text));
            }else{
                  
    $this->message  '--' $this->boundary $this->eol;
                  
    $this->message .= 'Content-Type: multipart/alternative; boundary="' $this->boundary '_alt"' $this->eol $this->eol;
                  
    $this->message .= '--' $this->boundary '_alt' $this->eol;
                  
    $this->message .= 'Content-Type: text/plain; charset="' $this->charset '"' $this->eol
                  
    $this->message .= 'Content-Transfer-Encoding: base64' $this->eol;      
                if(!empty(
    $this->text)){
                    
    $this->message .= chunk_split(base64_encode($this->text));
                }else{
                    
    $this->message .= chunk_split(base64_encode('This E-Mail contains HTML but your email client does not support HTML'));
                  }    
          
                  
    $this->message .= '--' $this->boundary '_alt' $this->eol;
                  
    $this->message .= 'Content-Type: text/html; charset="' $this->charset '"' $this->eol
                  
    $this->message .= 'Content-Transfer-Encoding: base64' $this->eol $this->eol;
                  
    $this->message .= chunk_split(base64_encode($this->html)); 
                
    $this->message .= '--' $this->boundary '_alt--' $this->eol
            }
            
            
    //Lets do some attachments
            
    foreach ($this->attachments as $attachment){
                
    $filename basename($attachment);
                if(!
    file_exists($attachment)){
                    
    trigger_error("Attachment <{$filename}> does not exists!",E_USER_ERROR);
                }
                
                
    //Continue to Fopen->Fread->Fclose
                
    $handle fopen($attachment'r');
                
    $content fread($handlefilesize($attachment));
                
    fclose($handle);
                
                
    $this->message .= '--' $this->boundary $this->eol;
                
    $this->message .= 'Content-Type: application/octetstream' $this->eol;
                
    $this->message .= 'Content-Transfer-Encoding: base64' $this->eol;
                
    $this->message .= 'Content-Disposition: attachment; filename="' $filename '"' $this->eol;
                
    $this->message .= 'Content-ID: <' $filename '>' $this->eol $this->eol;
                
    $this->message .= chunk_split(base64_encode($content));
            }

            
    //Now lets send the mail via PHPMAIL
            
    ini_set('sendmail_from'$this->from);
            
    mail($this->to$this->subject$this->message$this->headers);
            
            
    /*
            *** SMTP sender may be created here depending on how many users wish for it.
            */
        
    }
    }
    ?>
    litewarez Reviewed by litewarez on . [PHP] E-mailer (Attachment Support) [/PHP] Heres a nice email class i createed that you can use in your projects and you can also add attachments to the email.... Key-Features: Simple OOP Plain-Text OR Html Formatted Use both Plain-Text and Html to help with unsupported clients Able to add attachments of any sort Based on PHP-Mail Multiple Recipients in one batch Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Too busy :|
    Website's:
    L337Fx.com BeastieBay.net
    WOW
    Fantastic Nice job litewarez

  4.     
    #3
    Member
    yea another A++ tutorial/script

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    thanks, i just thought that alot of users have issues with headers etc with php's mail() function so thought id make a class to make everything simpler for you all... alsop this is released under GPL no and will be available on phpclasses soon
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    (╯?□?)╯︵ ┻━┻
    Website's:
    Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.com
    pretty useful class but try to use isset() or empty() in your if statements rather than checking if it is false (!$). Empty is probably best.

    Reason being, you can have a var set to a value which is seen as false.
    Projects:
    WCDDL - The Professional DDL Script
    Top Secret Project: In Development - ZOMG
    ImgTrack - Never Have Dead Images Again!

  7.     
    #6
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Yea i dont know why i did not do that in the beginning :/ prob because i thought they would be set with the protected declaration.. thanks anyhow, ill use empty
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  8.     
    #7
    (╯?□?)╯︵ ┻━┻
    Website's:
    Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.com
    Yeah, I was going to suggest isset() but I remembered empty() returns true for declared vars without values (e.g. protected $var; ).

    So thats best for this situation.
    Projects:
    WCDDL - The Professional DDL Script
    Top Secret Project: In Development - ZOMG
    ImgTrack - Never Have Dead Images Again!

  9.     
    #8
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    yea i would have used isset but then the vars are already declared sooo empty is more appropriate thanks tho bud
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  10.     
    #9
    Member
    Neat, clean code, I like it.

    One thing, some hosts have ini_set() disabled (I know I do on most shared hosting machines), perhaps specify the sender in an additional parameter to mail().
    ...

  11.     
    #10
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    To be honest i cant believe i missed that parameter lol... may change it thanks voltage
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Image Attachment Permission ?
    By Noob in forum vBulletin
    Replies: 10
    Last Post: 13th Jan 2012, 11:01 AM
  2. redirect to home page when download attachment
    By bluedevil in forum vBulletin
    Replies: 3
    Last Post: 20th Aug 2011, 07:37 AM
  3. Attachment problem!!!!!!!
    By Noob in forum vBulletin
    Replies: 2
    Last Post: 10th Jul 2011, 03:24 PM
  4. Attachment file size
    By Spooky in forum IP.Board
    Replies: 4
    Last Post: 13th Sep 2010, 03:48 PM
  5. [TUT]Setting / Adjusting Attachment Limits
    By Lease in forum IP.Board
    Replies: 0
    Last Post: 13th Jan 2008, 01:23 AM

Tags for this Thread

BE SOCIAL