Advertisement
Guest User

CodeIgniter TLS Email Example

a guest
Feb 13th, 2013
3,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2.         $config = Array(
  3.             'protocol'    => 'smtp',
  4.             'smtp_host'   => $smtp['mail_server'],
  5.             'smtp_port'   => $smtp['port'],
  6.             'smtp_user'   => $smtp['mail_username'],
  7.             'smtp_pass'   => $smtp['mail_password'],
  8.             'smtp_crypto' => ($smtp['tls'] == 0 ? NULL : 'tls'),
  9.             'mailtype'    => 'text',
  10.             'charset'     => 'iso-8859-1'
  11.         ); 
  12.        
  13.         $this->load->library('email');
  14.         $this->email->clear();
  15.         $this->email->initialize($config);
  16.         $this->email->set_newline("\r\n");
  17.  
  18.         // Set to, from, message, etc.
  19.  
  20.         $this->email->from($smtp['fromemail'], $smtp['fromname']);
  21.         $this->email->to( $to );
  22.         if($page != 'useradmin')
  23.         {
  24.             $this->email->cc( array($this->session->userdata('LoginEmailAddress'), $smtp['fromemail']));
  25.         }
  26.        
  27.         if( $cc )
  28.         {
  29.             $this->email->cc( $cc );
  30.         }
  31.  
  32.         if( $bcc )
  33.         {
  34.             $this->email->bcc( $bcc );
  35.         }
  36.  
  37.         if( $attach )
  38.         {
  39.             if( is_array($attach) )
  40.             {
  41.                 foreach( $attach as $location )
  42.                 {
  43.                     $this->email->attach( $location );
  44.                 }
  45.             }
  46.             else
  47.             {
  48.                 $this->email->attach( $attach );
  49.             }
  50.         }
  51.  
  52.         $this->email->subject( $subject );
  53.         $this->email->message( $body );
  54.         return $this->email->send();
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement