codeigniter 3 smtp email send

CodeIgniter Email Configuration
We need to have a central place where we can manage the email settings. CodeIgniter does not come with a config file for emails so we will have to create one ourselves.

Create a file email.php in the directory application/config

Add the following code to email.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');

$config = array(
    'protocol' => 'smtp', // 'mail', 'sendmail', or 'smtp'
    'smtp_host' => 'smtp.example.com', 
    'smtp_port' => 465,
    'smtp_user' => '[email protected]',
    'smtp_pass' => '12345!',
    'smtp_crypto' => 'ssl', //can be 'ssl' or 'tls' for example
    'mailtype' => 'text', //plaintext 'text' mails or 'html'
    'smtp_timeout' => '4', //in seconds
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
);
?>
HERE,
'protocol' => 'smtp', specifies the protocol that you want to use when sending email. This could be Gmail smtp settings or smtp settings from your host
'smtp_host' => 'smtp.example.com',specifies the smtp host. For example, if you want to use Gmail then you would have something like smtp.gmail.com
'smtp_port' => 465, an open port on the specified smtp host that has been configured for smtp mail
'smtp_user' => '[email protected]', the email address that will be used as the sender when sending emails. This should be a valid email address that exists on the server
'smtp_pass' => '12345!', the password to the specified smtp user email
'smtp_crypto' => 'ssl', specifies the encryption method to be used i.e. ssl, tls etc.
'email type' => 'text', sets the mail type to be used. This can be either plain text or HTML depending on your needs.
'smtp_timeout' => '4', specifies the time in seconds that should elapse when trying to connect to the host before a timeout exception is thrown.
'charset' => 'iso-8859-1', defines the character set to be used when sending emails.
'wordwrap' => TRUE is set to TRUE then word-wrap is enabled. If it is set to FALSE, then word-wrap is not enabled

<?php 
  $this->load->config('email');
  $this->load->library('email');

  $from = $this->config->item('smtp_user');
  $to = $this->input->post('to');
  $subject = $this->input->post('subject');
  $message = $this->input->post('message');

  $this->email->set_newline("\r\n");
  $this->email->from($from);
  $this->email->to($to);
  $this->email->subject($subject);
  $this->email->message($message);

  if ($this->email->send()) {
    echo 'Your Email has successfully been sent.';
  } else {
    show_error($this->email->print_debugger());
  }  
?>

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
send html mail using smtp in codeigniter send mail in codeigniter without smtp send email codeigniter 4 smtp email form codeigniter codeigniter 3.1.7 send email codeigniter 3 smtp mail send email using smtp codeigniter codeigniter version 3 mail sending to in email of codeigniter 3 email how to send email using codeigniter 4 how to configure smtp server to send email in codeigniter codeigniter 4 email send codeigniter 4 your server to send email email codeigniter 4 smtp codeigniter 4 send html email smtp settings for sending email through codeigniter codeigniter send email from server how to send email from server codeigniter without smtp codeigniter 3 send email codeigniter email configuration smtp email send in codeigniter 3 smtp mail setup codeigniter codeigniter 3 mailtrap smtp codeigniter smtp mail send codeigniter 3 custom email send from controller send email from codeigniter 4 codeigniter smtp send email with attachment sending email through codeigniter 3 codeigniter smtp email protocol codeigniter 4 sending email send email in codeigniter with smtp how to send email in codeigniter 4 send email in codeigniter 3.1 codeigniter send using microsoft mail smtp send smtp mail in php codeigniter setting codeigniter to send email using smtp webmail setting codeigniter to send email using smtp send email codeigniter 3 with view send email in codeigniter 3 send email with smtp codeigniter codeigniter email smtp send email from codeigniter smtp codeigniter smtp from to same email without smtp how to send the mail in codeigniter local send mail in codeigniter using smtp how to use smtp to send email in codeigniter codeigniter 4 send email example codeigniter 3 send email smtp codeigniter 4 send email codeigniter 3 email codeigniter 4 send email without smtp codeigniter 3 mail whenever sending email using codeigniter whenever send email using codeigniter library codeigniter send mail to webmail server codeigniter email settings clear codeigniter SMTP Secure auto codeigniter SMTPSecure email confifure in codeigniter ci send mail library host gmail codeignitor mail send codeigniter email library codeigniter email library codeigniter send email without smtp codeigniter email send example codeigniter send email via moddel codeigniter send email via model codeigniter ecommerce order email sending create test mail smtp codeigniter how to send data to mail in php codeigniter how to send email when user subscription in codeigniter how to send data to mail from backend in php codeigniter sendmail in email codeigniter codeigniter send email smtp how to make configurasi email in codeigniter send email in codeigniter using smtp ci email send codeigniter email config email in codeigniter 3 how to send email using codeigniter send mail in codeigniter using smtp codeigniter email how to send mail in codeigniter smtp server settings for webmail codeigniter email sendmail smtp server settings for webmail codeigniter email send html email in codeigniter Non-SSL Settings send mail settings in codeigniter sendmail libraru Setting Email configuration file Preferences codeigniter 3 email config codeigniter set email send by server email id in codeigniter mail function in codeigniter codeigniter 3 email from database codeigniter email configuration how to send email in codeigniter using smtp codeigniter send email smtp mail configuration in codeigniter sent email relay codeigniter configure webmail in codeigniter mailer ci codeigniter mail server email codeigniter send mail copy codeigniter using smtp send mail with codeigniter smtp smtp mail in content ci how to send email in php using codeigniter hoooking up email codeiginitor send email using smtp in codeigniter send mail using roundcube in codeignite email setup in codeigniter how can send email in codeigniter how can send email in codeigniter using smtp how to send emails using codeigniter send email in codeigniter Send email via SMTP server in CodeIgniter php mail codeigniter codeigniter 3 send email from class send email codeigniter 3 send email library codeigniter php codeigniter config email configure email in codeigniter email config in codeigniter send email using codeigniter 3 codeigniter send mail ci email attach buffered content how to call codeigniter library email how to call codeigniter library email in controller view file is not going in mail codeigniter sending email codeigniter sent email code igniter send email using smtp in codeigniter 3 how to send email using codeigniter smtp gmail account send mail in codeigniter codeigniter mail sending code
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source