Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
By: CodexWorld In: CodeIgniter Last Updated: Dec 19, 2018 Share Tweet
ENTER YOUR EMAIL...
SUBSCRIBE
Send Email using PHPMailer in CodeIgniter
CodeIgniter’s Email class is the simplest way to send email in CodeIgniter application. Not only the text/html email but also you can send the email via SMTP server
using CodeIgniter Email library. This Email class is a system library and comes with the CodeIgniter framework. So, it can be easily used in the CodeIgniter application
without an additional library. Alternatively, PHPMailer library is the best option to send email via SMTP server without using the CodeIgniter default Email library.
Generally, PHPMailer library is used to send email with SMTP server in PHP. You can also use the PHPMailer library in CodeIgniter framework to send email using
SMTP server. In this tutorial, we will show you how to integrate PHPMailer in CodeIgniter 3 application and send email via SMTP server using PHPMailer in
CodeIgniter.
application/
Login with Google Account using PHP
└── third_party/
└── PHPMailer/ PayPal Standard Payment Gateway Integration in PHP
├── Exception.php
Dynamic Dependent Select Box using jQuery, Ajax and PHP
├── OAuth.php
├── PHPMailer.php Add Remove Input Fields Dynamically using jQuery
├── POP3.php
└── SMTP.php Autocomplete Textbox using jQuery, PHP and MySQL
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class PHPMailer_Lib
{
public function __construct(){
log_message('Debug', 'PHPMailer class is loaded.');
}
Using PHPMailer_Lib library you can send email with PHPMailer in your CodeIgniter application. The following example code shows how to send email via SMTP server
How to Trigger Button Click on Enter Key Press using JavaScript
using PHPMailer from the controller of the CodeIgniter application.
How to Extract Content Between HTML Tags using PHP
Load the PHPMailer_Lib library.
How to Bind jQuery Click Event on Ajax Loaded Content
Call the load() function of PHPMailer_Lib.
Specify the host ( $mail‐>Host ), username ( $mail‐>Username ), password ( $mail‐>Password ), and port ( $mail‐>Port ) as per your SMTP server credentials.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
function __construct(){
parent::__construct();
}
function send(){
// Load PHPMailer library
$this‐>load‐>library('phpmailer_lib');
// PHPMailer object
$mail = $this‐>phpmailer_lib‐>load();
// SMTP configuration
$mail‐>isSMTP();
$mail‐>Host = 'smtp.example.com';
$mail‐>SMTPAuth = true;
$mail‐>Username = 'user@example.com';
$mail‐>Password = '********';
$mail‐>SMTPSecure = 'ssl';
$mail‐>Port = 465;
$mail‐>setFrom('info@example.com', 'CodexWorld');
$mail‐>addReplyTo('info@example.com', 'CodexWorld');
// Add a recipient
$mail‐>addAddress('john.doe@gmail.com');
// Add cc or bcc
$mail‐>addCC('cc@example.com');
$mail‐>addBCC('bcc@example.com');
// Email subject
$mail‐>Subject = 'Send Email via SMTP using PHPMailer in CodeIgniter';
// Send email
if(!$mail‐>send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail‐>ErrorInfo;
}else{
echo 'Message has been sent';
}
}
You can use Gmail SMTP to sending email with PHPMailer in CodeIgniter. Before getting started with Gmail SMTP, some changes are needed in your Google account
settings to use Gmail SMTP.
2. Click the Signing in to Google link under the Sign-in & security section.
3. Scroll down to Password & sign-in method section and turn Off the 2-Step Verification.
4. Scroll down to Apps with account access section and turn on Allow less secure apps.
You are done! Now Google will allow you to use Gmail SMTP for sending email from the PHP script of your CodeIgniter application.
Specify your Gmail account’s email address as username ( $mail‐>Username ), password ( $mail‐>Password ), SMTP host and port.
// SMTP configuration
$mail‐>isSMTP();
$mail‐>Host = 'smtp.gmail.com';
$mail‐>SMTPAuth = true;
$mail‐>Username = 'codexworld@gmail.com';
$mail‐>Password = '********';
$mail‐>SMTPSecure = 'tls';
$mail‐>Port = 587;
Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request
PHP in PHP
Leave a reply
Comment *
Post Comment
Copyright © 2019 CodexWorld. All rights reserved. About Us | Privacy Policy | Terms & Conditions | Write For Us | Advertise | Contact