CodeIgniter is a very famous MVC framework that is widely used all over the world while making dynamic websites on php. Almost all kind of libraries are there to meet your requirement. Same as php-mailer. We can send email in codeigniter with php-mailer same as we did in core php. For that we will use codeigniter-phpmailer that is highly customized for the Codeigniter framework , it is very easy to implement i’ll show you the procedure step by step.
Step 1:
Download the package of Codeigniter-Phpmailer Download Here
Step 2:
Extract the package, copy all the files and paste it in application folder in your codeigniter.
Step 3:
application/config/email.php
You will now have a email.php file to configure email settings as per your preferences.
<?php defined('BASEPATH') OR exit('No direct script access allowed.'); $config['useragent'] = 'PHPMailer'; // Mail engine switcher: 'CodeIgniter' or 'PHPMailer' $config['protocol'] = 'mail'; // 'mail', 'sendmail', or 'smtp' $config['mailpath'] = '/usr/sbin/sendmail'; $config['smtp_host'] = ''; $config['smtp_user'] = ''; $config['smtp_pass'] = ''; $config['smtp_port'] = ; $config['smtp_timeout'] = 30; // (in seconds) $config['smtp_crypto'] = ''; // '' or 'tls' or 'ssl' $config['smtp_debug'] = 0; // PHPMailer's SMTP debug info level: 0 = off, 1 = commands, 2 = commands and data, 3 = as 2 plus connection status, 4 = low level data output. $config['smtp_auto_tls'] = true; // Whether to enable TLS encryption automatically if a server supports it, even if `smtp_crypto` is not set to 'tls'. $config['smtp_conn_options'] = array(); // SMTP connection options, an array passed to the function stream_context_create() when connecting via SMTP. $config['wordwrap'] = true; $config['wrapchars'] = 76; $config['mailtype'] = 'html'; // 'text' or 'html' $config['charset'] = null; // 'UTF-8', 'ISO-8859-15', ...; NULL (preferable) means config_item('charset'), i.e. the character set of the site. $config['validate'] = true; $config['priority'] = 3; // 1, 2, 3, 4, 5; on PHPMailer useragent NULL is a possible option, it means that X-priority header is not set at all, see https://github.com/PHPMailer/PHPMailer/issues/449 $config['crlf'] = "\n"; // "\r\n" or "\n" or "\r" $config['newline'] = "\n"; // "\r\n" or "\n" or "\r" $config['bcc_batch_mode'] = false; $config['bcc_batch_size'] = 200; $config['encoding'] = '8bit'; // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'. // DKIM Signing // See https://yomotherboard.com/how-to-setup-email-server-dkim-keys/ // See http://stackoverflow.com/questions/24463425/send-mail-in-phpmailer-using-dkim-keys // See https://github.com/PHPMailer/PHPMailer/blob/v5.2.14/test/phpmailerTest.php#L1708 $config['dkim_domain'] = ''; // DKIM signing domain name, for exmple 'example.com'. $config['dkim_private'] = ''; // DKIM private key file path. $config['dkim_selector'] = ''; // DKIM selector. $config['dkim_passphrase'] = ''; // DKIM passphrase, used if your key is encrypted. $config['dkim_identity'] = '';
Step 4:
After setting your email preferences you can send emails by php mailer in your controller easily. Just have a look of it.
public function mycontroller(){ $this->load->library('email'); $this->email->from('you@example.com', 'Your Name'); $this->email->to('someone@example.com'); $this->email->subject('This is my subject'); $this->email->message('This is my message'); $this->email->send(); }
This is how you emails will be send by php mailer codeigniter version. If you wan’t to have more options to send emails go through this link. click here