Showing posts with label send email using SMTP config in codeigniter 3. Show all posts
Showing posts with label send email using SMTP config in codeigniter 3. Show all posts

Saturday 17 September 2016

send email using SMTP config in codeigniter 3

Hello

send email using SMTP config in codeigniter 3

here example how to setup SMTP in codeigniter 3

first download the php mailler

put after extract foleder phpmailer folder move to codeigniter in application\libraries

after create libraries in  application\libraries create file my_phpmailer.php

here the code of my_phpmailer.php file

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_PHPMailer {
    public function My_PHPMailer() {
        require_once('PHPMailer/PHPMailerAutoload.php');
    }
   
   


}

3) Go To application\helpers create file  sendemails_helper.php

her code of header 


if(!function_exists('send_emails'))
    {
             function send_emails($emails,$body,$subject){
                    $mail = new PHPMailer;
                   
                    $mail->isSMTP();      
                    $mail->Host = 'smtp.mail.yahoo.com';  //                               // Set mailer to use SMTP
                   
                    $mail->SMTPAuth = true;                               // Enable SMTP authentication
                    $mail->Username = 'yahoomail';                 // SMTP username
                    $mail->Password = 'yahoopassword';                           // SMTP password
                    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
                    $mail->Port = 465;                                    // TCP port to connect to
                   
                    $mail->setFrom('jhparmar87@yahoo.com', 'title name');
                   
                   
                    $mail->addAddress($emails, 'user');
               
                   
                    $mail->isHTML(true);                                  // Set email format to HTML
                   
                    $mail->Subject = $subject;
                    $mail->MsgHTML($body);
                   
                    $mail->send();
           
             }
    }

after go to application\config open the file autoload.php

$autoload['libraries'] = array('database','session','My_PHPMailer');// here add you library My_PHPMailer

$autoload['helper'] = array('url', 'file','form','sendemails');// here add you helper file  sendemails

after when controler you want to send mail from smtp setup this helper function

    send_emails("test@yahoo.com","body content","subject"); 

here fully exmple of send email using SMTP config in codeigniter 3 please check it now