View Single Post
  #2 (permalink)  
Old 07-01-09, 10:38 PM
windows7 windows7 is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:
<?php
class Email
{
    public 
$fromName;
    public 
$fromAdd;    
    public 
$to;
    public 
$subject;
    public 
$content;    
    
    public 
$smtpEnable;
    public 
$host;
    public 
$port;
    public 
$username;
    public 
$password;
    
    function 
Email() // Constructor
    
{
        
/* 
        START: Get SMTP infomantion from App configuration 
        those config should be load from Prado application.xml
        Please rewrite carefully
        */
        
$this->smtpEnable    = (bool) $this->Application->Parameters['smtpEnable'];
        
$this->host            $this->Application->Parameters['smtpHost'];
        
$this->port            $this->Application->Parameters['smtpPort'];
        
$this->username        $this->Application->Parameters['smtpUsername'];
        
$this->password        $this->Application->Parameters['smtpPassword'];
        
//* END: Get SMTP infomantion from App configuration */

        
$this->fromName    $this->Application->Parameters['noReplyName'];
        
$this->fromAdd    $this->Application->Parameters['noReplyAddress'];
        
$this->to        NULL;
        
$this->subject    NULL;
        
$this->content    NULL;    
    }
    
    public function 
sendByPhp()
    {
        
$headers  "MIME-Version: 1.0" "\r\n";
        
$headers .= "Content-type: text/html; charset=utf-8" "\r\n";
        
$headers .= "From: ".$this->fromName." <".$this->fromAdd.">" "\r\n";
        if(!
mail($this->to$this->subject$this->content$headers)) return false;
        return 
true;
    }
    
    public function 
sendBySmtp()
    {
        require_once 
"Mail.php";

        
$headers = array(
                        
"MIME-Version"     => "1.0",
                        
"Content-type"     => "text/html; charset=utf-8",
                        
"From"            => $this->fromName." <".$this->fromAdd.">"
                        
"To"             => $this->to,                         
                        
"Subject"        => $this->subject
                    
);
    
        
$smtp Mail::factory(
            
"smtp",    array (
                
"host"         => $this->host,
                
"auth"         => true,
                
"port"         => $this->port,
                
"username"     => $this->username,
                
"password"     => $this->password
            
)
        );
        
        
$mail $smtp->send($this->to$headers$this->content);
        if (
PEAR::isError($mail)) return false;
        return 
true;
    }
    
    public function 
send()
    {
        if(
$this->smtpEnable
        {
            if(
$this->sendBySmtp()) return true;
        }
        else
        {
            if(
$this->sendByPhp()) return true;
        }
        return 
false;
    }
}
?>
Using:
PHP Code:
$e = new Email();
$e->subject='Subject';
$e->content='message';

$e->to="email1@yahoo.com, ";
$e->send();

$e->to="email2@yahoo.com, ";
$e->send(); 
Reply With Quote