0

today i have sending email using code igniter but not work properly .so please any one help me.

this is my controller page code here;

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

class Welcome extends CI_Controller {enter code here

  function __construct() {
  parent::__construct();
   
    $this->load->helper(array('form', 'url'));
     // $this->load->library('pagination');
   $this->load->library('session','form_validation');
  }  
  
function sendMail() 
{ 
$config = Array( 
'protocol' => 'smtp', 
'smtp_host' => 'ssl://smtp.gmail.com', 
'smtp_port' => 465, 
'smtp_user' => 'siva@gmail.com', // here goes your mail 
'smtp_pass' => 'mygamilpassword', // here goes your mail password 
'mailtype' => 'html', 
'charset' => 'iso-8859-1', 
'wordwrap' => TRUE 
);
 $this->email->initialize($config);    
$message = 'hiiiiii'; 
$this->load->library('email', $config); 
$this->email->set_newline("rn"); 
$this->email->from('siva@gmail.com'); // here goes your mail 
$this->email->to('sam@gmail.com');// here goes your mail 
$this->email->subject('Resume from JobsBuddy'); 
$this->email->message($message); 
if($this->email->send()) 
{ 
echo 'Email sent.'; 
} 
else 
{ 
show_error($this->email->print_debugger()); 
}
} $this->sendMail;
  } 

and in my localhost open php.extension->php.openssl enable and also the port number change for 465, and smtp:smtp.gmail.com this are all enable it.

but not working help me.?

sivakumar.s
  • 87
  • 1
  • 2
  • 14
  • possible duplicate of [Send email by using codeigniter library via localhost](http://stackoverflow.com/questions/18586801/send-email-by-using-codeigniter-library-via-localhost) – Vidya Sagar Jun 20 '15 at 05:59
  • This question may help http://stackoverflow.com/questions/29735568/codeigniter-contact-form-email/29737132#29737132 –  Jun 20 '15 at 07:00
  • Check this [link](http://stackoverflow.com/questions/7246158/how-to-solve-the-send-mail-slow-in-codeigniter/30660271#30660271) – Bugfixer Jun 22 '15 at 07:09

2 Answers2

0

Try this code. This is the working code:

function sendMail() 
{ 
    $config['protocol'] = "smtp";
    $config['smtp_host'] = "ssl://smtp.googlemail.com";
    $config['smtp_port'] = "465";
    $config['smtp_user'] = "siva@gmail.com";
    $config['smtp_pass'] = "mygamilpassword";

    $message = "Your email body text goes here";

    $config['mailtype'] = "html";
    $ci = & get_instance();
    $ci->load->library('email', $config);
    $ci->email->set_newline("\r\n");
    $ci->email->from("siva@gmail.com");
    $ci->email->to("siva@gmail.com");
    $ci->email->subject("Resume from JobsBuddy");
    $ci->email->message($message);
    $ci->email->send();  
    echo $this->email->print_debugger();
}
TheLethalCoder
  • 6,668
  • 6
  • 34
  • 69
Anam Shah
  • 319
  • 1
  • 10
  • hi anam shah, this code not working.because this error comes – sivakumar.s Jun 22 '15 at 07:51
  • From: Return-Path: Reply-To: "sivaprocessdrive@gmail.com" X-Sender: sivaprocessdrive@gmail.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <5587bdecd4f0a@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit =?utf-8?Q?Resume_from_siva?= Your email body text goes here – sivakumar.s Jun 22 '15 at 07:51
  • comment the last line – Anam Shah Jun 22 '15 at 07:58
  • echo $this->email->print_debugger();...then check your mail ....this line prints the debugging for email – Anam Shah Jun 22 '15 at 07:58
  • @sivakumar.s can you provide the site url – Mitul Jun 22 '15 at 08:00
  • I have found the article which demonstrate how to send emails in a CodeIgniter application using SMTP. https://www.cloudways.com/blog/send-email-codeigniter-smtp/ – Owais Alam Aug 23 '17 at 13:12
0

Try this code. This is the working code and allow-less-secure-apps-access-gmail-account setting open

public function send_mail() {

    ini_set('SMTP', "server.com");
    ini_set('smtp_port', "25");
    ini_set('sendmail_from', "yourmail@gmail.com");

    $this->load->library('email');

    $this->load->library('email');

    $config['protocol']    = 'smtp';
    $config['smtp_host']    = 'ssl://smtp.gmail.com';
    $config['smtp_port']    = '465';
    $config['smtp_timeout'] = '7';
    $config['smtp_user']    = 'yourmail@gmail.com';
    $config['smtp_pass']    = 'yourpassword';
    $config['charset']    = 'utf-8';
    $config['newline']    = "\r\n";
    $config['mailtype'] = 'text'; // or html
    $config['validation'] = TRUE; // bool whether to validate email or not
    $this->email->initialize($config);

    $this->email->set_newline("\r\n");

    $from_email = "frommailid@gmail.com";
    $to_email = "tomailid@gmail.com";
    //Load email library
    $this->load->library('email');
    $this->email->from($from_email, 'Identification');
    $this->email->to($to_email);
    $this->email->subject('Send Email Codeigniter');
    $this->email->message('The email send using codeigniter library');
    //Send mail
    if($this->email->send())
        $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
    else
        show_error($this->email->print_debugger());
        $this->session->set_flashdata("email_sent","You have encountered an error");
    $this->load->view('contact_email_form');
} 
Ashok
  • 1
  • 2