-2

hello all i have to send email on localhost and following is my config file

$config['useragent']      = "CodeIgniter";
$config['mailpath']       = "/usr/sbin/sendmail -t -i";
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'xyz.com'; //change this
$config['smtp_port'] = '465';
$config['smtp_user'] = 'xyz.com'; //change this
$config['smtp_pass'] = '######'; //change this
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard

i create code follwing code for email send

if(count($result) > 0 || $result != NULL){
                    $password=$result['password'];
                    $this->load->library('email');
                    $from='chirag@site.com';
                    $to=$email;
                    $subject='forget password';                        
                    $this->email->from($from);
                    $this->email->to($to);
                    $this->email->subject($subject);
                    $this->email->message($password);
                    if($this->email->send()){
                        $this->session->set_flashdata('email','We sent your password to your Email...!');
                        redirect('login');
                    }
                    else{            
                        echo $this->email->print_debugger();
                    }
            }

but i got following error when i send email

The following SMTP error was encountered: 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

so what is problem there? please help me to solve

Keyur Chavda-kc1994
  • 1,045
  • 1
  • 13
  • 28

2 Answers2

1

i got answer there is missing a ssl:// in config but after writing following

$config['smtp_host'] = 'ssl://xyz.com';

mail is send successfully...

Keyur Chavda-kc1994
  • 1,045
  • 1
  • 13
  • 28
1

First make sure you already done the proper localhost configuration for sending emails. Then in your controller you load the email library by setting the appropriate credentials and port number. Like so:

$config = Array(
                            'protocol' => 'smtp',
                            'smtp_host' => 'ssl://smtp.gmail.com',
                            'smtp_port' => 465,
                            'smtp_user' => 'your_gmail_name@gmail.com', 
                            'smtp_pass' => 'your_pass', 
                            //'mailtype' => 'html',
                            // 'charset' => 'iso-8859-1',
                            // 'wordwrap' => TRUE
                        );
                        $this->load->library('email', $config); 
Community
  • 1
  • 1
Petko Kostov
  • 367
  • 1
  • 9