לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 30-07-2008, 22:35
  משתמש זכר vadim88 vadim88 אינו מחובר  
 
חבר מתאריך: 14.04.06
הודעות: 331
מחלקה ב PHP לשליחת אימייל כולל תמיכה בHTML וצירוף קבצים

לא ראיתי נושא שמאפשר צירוף של מחלקות שלמות לביצוע פעולות מסויימות וחבל. אז לכל מי שמעוניין זה משהו שנכתב על ידי ומשומש בצורה קבוע לצורך שליחת אימיילים בקלות ויעילות.

תמיכה ב HTML, קידוד, ואפשרות לצרף קבצים.

אם משהו מעוניין לערוך משהו הוא מוזמן.

קוד PHP:
<?php

/*---------------------------------------
// Class Email Version 1.0
// Written by vadim gavrilov (vadimg88@gmail.com)
// $ Date started june 28th 2008
// $ Revision 122
// Contact: vadimg88@gmail.com
----------------------------------------*/

/*

USAGE:

Simple email send:

require_once('class.email.php');
$email = new email;

$email->from = ''; // Senders email address
$email->to = ''; // who will get the email
$email->msg = ''; // email message (html enabled)

$email->sendmail(); // send email!

ADDING ATTACHMENTS:

$email->add_attachment(); // 3 arguments 1. the actuall attachemnt file 2. the attachment name 3. the type

TO ADD MULTIPLE ATTACHMENTS JUST COPY AND PASTE THE LINE ABOVE MULTIPLE TIMES, EX:

$email->add_attachment('data','name','type');
$email->add_attachment('data','name','type');
$email->add_attachment('data','name','type');




*/

/**
* Main Email Class.
*
* This class holds all the email related functions.
*
* @author   vadim gavrilov
* @version    1.0
*/

class email
{
    
    
# Global Vars
    
var $mail_headers "";
    var 
$bcc = array();
    var 
$to "";
    var 
$from "";
    var 
$msg "";
    var 
$crlf;
    var 
$header "";
    var 
$footer "";
    var 
$boundry "";
    var 
$parts = array();
    var 
$multipart    "";

    
// Editable Vars
    
var $email_from 'youremail@domain.com'// default email from 
    
var $char_set "windows-1255"// default email char' set
        
    
function email()
    {
        
$this->email_init();
    }

    function 
email_init()
    {
        
$this->header "";
        
$this->footer "";
        
$this->boundry 'PHP' md5(uniqid(time()));
        
$this->from $this->email_from;
    }

    function 
build_headers()
    {

        
$this->mail_headers .= "MIME-Version: 1.0\n";
        
$this->mail_headers .= "Content-type: text/html; charset=\"".$this->char_set."\"\n";

        
$this->mail_headers  .= "From: <".$this->from.">\n";


        if ( 
count$this->bcc ) > )
        {
            
$this->mail_headers .= "Bcc: ".implode"," $this->bcc ) . "\n";
        }


        if ( 
$this->to )
        {
            
$this->mail_headers .= "To: ".$this->to."\n";
        }
        
$this->mail_headers .= "Subject: ".$this->subject."\n";


        
//-----------------------------------------
        // we're not spam, really!
        //-----------------------------------------

        
$this->mail_headers .= "Return-Path: ".$this->from."\n";
        
$this->mail_headers .= "X-Priority: 3\n";
        
$this->mail_headers .= "X-Mailer: Rent Center Mailer\n";

        
//-----------------------------------------
        // Count.. oh you get the idea
        //-----------------------------------------

        
if ( count ($this->parts) > )
        {
            
$this->mail_headers .= "MIME-Version: 1.0\n";
            
$this->mail_headers .= "Content-Type: multipart/mixed;\n\tboundary=\"".$this->boundry."\"\n\nThis is a MIME encoded message.\n\n--".$this->boundry;
            
$this->mail_headers .= "\nContent-Type: text/html;\n\tcharset=\"".$this->char_set."\"\nContent-Transfer-Encoding: quoted-printable\n\n".$this->message."\n\n--".$this->boundry;

            
$this->mail_headers .= $this->build_multipart();

            
$this->message "";
        }

    }

    function 
sendmail()
    {

        
//-----------------------------------------
        // Wipe ya face
        //-----------------------------------------

        
$this->to   preg_replace"/[ \t]+/" ""  $this->to   );
        
$this->from preg_replace"/[ \t]+/" ""  $this->from );

        
$this->to   preg_replace"/,,/"     ","  $this->to );
        
$this->from preg_replace"/,,/"     ","  $this->from );

        
$this->to     preg_replace"#\#\[\]'\"\(\):;/\$!£%\^&\*\{\}#" ""$this->to  );
        
$this->from   preg_replace"#\#\[\]'\"\(\):;/\$!£%\^&\*\{\}#" ""$this->from);

        
//-----------------------------------------
        // Build headers
        //-----------------------------------------

        
$this->build_headers();

        
//-----------------------------------------
        // Lets go..
        //-----------------------------------------

        
if ( @mail$this->to$this->subject$this->message$this->mail_headers ) )
        {
            return 
TRUE;
        }

        
# Reset vars
        
$this->to           "";
        
$this->from         "";
        
$this->message      "";
        
$this->subject      "";
        
$this->mail_headers "";

        
$this->email_init();

    }

    function 
add_attachment($data ""$name ""$ctype='application/octet-stream')
    {

        
$this->parts[] = array( 'ctype'  => $ctype,
        
'data'   => $data,
        
'encode' => 'base64',
        
'name'   => $name
        
);
    }

    function 
encode_attachment($part)
    {

        
$msg chunk_split(base64_encode($part['data']));

        return 
"Content-Type: ".$part['ctype']. ($part['name'] ? ";\n\tname =\"".$part['name']."\"" "").
        
"\nContent-Transfer-Encoding: ".$part['encode']."\nContent-Disposition: attachment;\n\tfilename=\"".$part['name']."\"\n\n".$msg."\n";

    }

    function 
build_multipart()
    {

        
$multipart "";

        for (
$i sizeof($this->parts) - $i >= $i--)
        {
            
$multipart .= "\n".$this->encode_attachment($this->parts[$i]) . "--".$this->boundry;
        }

        return 
$multipart "--\n";

    }


}

?>


ואדים.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 14:04

הדף נוצר ב 0.07 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר