
The first thing download the library
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/
move folder /system/application/libraries
create a new PHP file in the CodeIgniter’s library directory called my_phpmailer.php
1 2 3 4 5 6 7 8 | <?php if ( ! defined( 'BASEPATH' )) exit ( 'No direct script access allowed' ); class My_PHPMailer { public function My_PHPMailer() { require_once( 'PHPMailer/class.phpmailer.php' ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php defined( 'BASEPATH' ) OR exit ( 'No direct script access allowed' ); class Phpmailer extends CI_Controller { public function My_Controller(){ parent::Controller(); $this ->load->library( 'My_PHPMailer' ); $this ->load->library( 'session' ); } function index( $msg = NULL) { $data [ 'message' ] = $msg ; $this ->load->view( 'contactus' , $data ); } public function send_mail() { $mail = new PHPMailer; //From email address and name $mail ->From = "from@yourdomain.com" ; $mail ->FromName = "Full Name" ; //To address and name $mail ->addAddress( "recepient1@example.com" , "Recepient Name" ); $mail ->addAddress( "recepient1@example.com" ); //Recipient name is optional //Address to which recipient will reply $mail ->addReplyTo( "reply@yourdomain.com" , "Reply" ); //CC and BCC $mail ->addCC( "cc@example.com" ); $mail ->addBCC( "bcc@example.com" ); //Send HTML or Plain Text email $mail ->isHTML(true); $mail ->Subject = "Subject Text" ; $mail ->Body = "<i>Mail body in HTML</i>" ; $mail ->AltBody = "This is the plain text version of the email content" ; if (! $mail ->send()) { $data [ "message" ] = "Error: " . $mail ->ErrorInfo; } else { $data [ "message" ] = "<p><h3>Message sent correctly!</h3></p>" ; } $this ->load->view( 'contactus' , $data ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "IE=edge" > <meta name= "viewport" content= "width=device-width, initial-scale=1" > <meta name= "description" content= "" > <meta name= "author" content= "" > <title>Codeigniter 3.1.10 Dev - Phpmailer </title> <link href= "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel= "stylesheet" id= "bootstrap-css" > <link href= "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel= "stylesheet" > </head> <body id= "page-top" class = "index" > <link href= "//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel= "stylesheet" id= "bootstrap-css" > <script src= "//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js" ></script> <script src= "//code.jquery.com/jquery-1.11.1.min.js" ></script> <link href= "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel= "stylesheet" > <section id= "contact" > <div class = "section-content" > <h1 class = "section-header" >Get in <span class = "content-header wow fadeIn " data-wow-delay= "0.2s" data-wow-duration= "2s" > Touch with us</span></h1> <h3>PHPMailer in CodeIgniter with bootstrap contact form</h3> </div> <div class = "contact-section" > <div class = "container" ><?php if (! is_null ( $message )) echo $message ;?> <form action= "send_mail" method= "post" > <div class = "col-md-6 form-line" > <div class = "form-group" > <label for = "exampleInputUsername" >Your name</label> <input type= "text" class = "form-control" id= "" placeholder= " Enter Name" > </div> <div class = "form-group" > <label for = "exampleInputEmail" >Email Address</label> <input type= "email" class = "form-control" id= "exampleInputEmail" placeholder= " Enter Email id" > </div> <div class = "form-group" > <label for = "telephone" >Mobile No.</label> <input type= "tel" class = "form-control" id= "telephone" placeholder= " Enter 10-digit mobile no." > </div> </div> <div class = "col-md-6" > <div class = "form-group" > <label for = "description" > Message</label> <textarea class = "form-control" id= "description" placeholder= "Enter Your Message" ></textarea> </div> <div> <button type= "submit" class = "btn btn-default submit" ><i class = "fa fa-paper-plane" aria-hidden= "true" ></i> Send Message</button> </div> </div> </form> </div> </section> <style> /*Contact sectiom*/ .content-header{ font-family: 'Oleo Script' , cursive; color:#fcc500; font-size: 45px; } .section-content{ text-align: center; } #contact{ font-family: 'Teko' , sans-serif; padding-top: 60px; width: 100%; width: 100vw; height: 550px; background: #3a6186; /* fallback for old browsers */ background: -webkit-linear-gradient(to left, #3a6186 , #89253e); /* Chrome 10-25, Safari 5.1-6 */ background: linear-gradient(to left, #3a6186 , #89253e); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */ color : #fff; } .contact-section{ padding-top: 40px; } .contact-section .col-md-6{ width: 50%; } .form-line{ border-right: 1px solid #B29999; } .form-group{ margin-top: 10px; } label{ font-size: 1.3em; line-height: 1em; font-weight: normal; } .form-control{ font-size: 1.3em; color: #080808; } textarea.form-control { height: 135px; /* margin-top: px;*/ } .submit{ font-size: 1.1em; float: right; width: 150px; background-color: transparent; color: #fff; } </style> </body> </html> |