[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 */