Send Email Using PHPMailer and Codeigniter
CodeIgniter Email Class built for handling double-byte characters is really bad, cannot be properly set up Charest UTF-8.
Here We want to share some information to use Codeigniter and PHPmailer together. In this way, you can send any type of codes in Email Body.
We have to follow few steps to use PHPmailer with CodeIgniter.
1- Download PHPmailer from original site.
2- Extract the downloaded “Zip” file.
3- Open the extracted file and copy “phpmailer.php” and “class.smtp.php”.
4- Paste these Two Files in Codeigniter Libraries.
5- Now create now controller as I have following one.
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Message extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->library('phpmailer');
}
function send_email() {
$subject = 'Testing Email';
$name = 'iQue Infotech';
$email = 'iqueinfotech@gmail.com';
$body = "This is body text for test email to combine CodeIgniter and PHPmailer";
$this->phpmailer->AddAddress($email);
$this->phpmailer->IsMail();
$this->phpmailer->From = 'xxxx@gmail.com';
$this->phpmailer->FromName = 'iQue Infotech';
$this->phpmailer->IsHTML(true);
$this->phpmailer->Subject = $subject;
$this->phpmailer->Body = $body;
$this->phpmailer->Send();
}
}
You simply need to pass values to this function and email is sent. To Read Simple PHPMailer to send email using PHP. Your controller is ready to send email using PHPMailer. This was simple, If you want to modify this controller, e.g you want to send html pages, you will kindly let me know, we will write another tutorial regarding this.
To Send An Email With Attachment We Need To Use The Multipart/mixed MIME Type That Specifies That Mixed Types Will Be Included In The Email. Moreover, We Want To Use Multipart/alternative MIME Type To Send Both Plain-text And HTML Version Of The Email.Have A Look At The Example:$filename = 'file'; $path = 'your Path Goes Here'; $file = $path . "/" . $filename;$mailto = 'to@mail.com'; $subject = 'Subject'; $message = 'My Message';$content = File_get_contents($file); $content = Chunk_split(base Continue
CodeIgniter Active Records Do Not Currently Support Sub-queries, However I Use The Following Approach: $this->db->select('id');$this->db->from('table');$where_clause = $this->db->_compile_select(false,true);$this->db->_reset_select();#Create Main Query$this->db->select('*');$this->db->from('table1');$this->db->where("`id` NOT IN ($where_clause)", NULL, FALSE);Return $this->db->get('',null,null,true); _compile_select() And _reset_ Continue
PHP Development Services In All Countries. With The Remarkable Experience, Our Experts Have Enabled Us To Become A Trusted PHP Development Service.Custom PHP DevelopmentWe Build Custom Websites That Carry Our Mark Of Excellence And Are In Complete Sync With Your BusinessPHP Based CMS DevelopmentWe Are Masters Of PHP And You Can Expect Unmatched PHP Based CMS Development For Your Business.PHP Web DevelopmentExperience PHP Web Development At Its Best With Us As We Take Care Of All Your Requi Continue