Welcome Guest, Not a member yet? Register   Sign In
In need of Email code. . .
#5

[eluser]JoJo17[/eluser]
Hi

I had trouble with my server setup and using Codeigniter's built-in email functions so I had to write my own library so I could send emails using PEAR. Feel free to use (and adjust as necessary) if you have similar issues:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email_functions {

private $smtp_params = array();

public function __construct()
{
  require_once "Mail.php";
  include('Mail/mime.php');
  
  
// Enter your SMTP authentication params here:
     $this->smtp_params['host']     = '';
     $this->smtp_params['port']     = '';
     $this->smtp_params['auth']     = '';
     $this->smtp_params['username'] = '';
     $this->smtp_params['password'] = '';
}


public function send_email($to,$from,$subject,$htmlBody,$attachment=NULL)
{
  
  $text = str_ireplace("<br />","\n", $htmlBody);
  $text = strip_tags($htmlBody);
  $crlf = "\n";
  
   $headers = array ('From' => $from,
     'To' => $to,
     'Subject' => $subject);
    
    // Creating the Mime message
       $mime = new Mail_mime($crlf);
      
      // Setting the body of the email
     $mime->setTXTBody($text);
     $mime->setHTMLBody($htmlBody);
     if ( ! empty($attachment)) $mime->addAttachment($attachment);

     $body = $mime->get();
     $headers = $mime->headers($headers);
    
  
    
    // Sending the email using smtp
        $mail =& Mail::factory('smtp', $this->smtp_params);
        $mail->send($to, $headers, $body);
        
          
            
        if (PEAR::isError($mail)) :
         return FALSE;
        else :
         return TRUE;
        endif;  

}


}
/* End of file Email_functions.php */
/* Location: ./application/libraries/email_functions.php */



Messages In This Thread
In need of Email code. . . - by El Forum - 11-09-2012, 02:12 AM
In need of Email code. . . - by El Forum - 11-09-2012, 04:23 AM
In need of Email code. . . - by El Forum - 11-09-2012, 05:19 AM
In need of Email code. . . - by El Forum - 11-09-2012, 05:32 AM
In need of Email code. . . - by El Forum - 11-11-2012, 09:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB