0

i'm trying to make sending email function using codeigniter but it doesn't work ,nothing is sent, there are any help?

This is my controller :

public function send_mail() { 

     $this->load->library('session'); 
     $this->load->helper('form'); 
     $this->load->view('admin/main/email_form.php');

    $config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxxxxx@gmail.com', 
    'smtp_pass' => 'xxxxxx',
    'mailtype' => 'html',
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE);

     $from_email = "xxxxxxx@gmail.com"; 
     $to_email = $this->input->post('email'); 
     $subject  = $this->input->post('subject');
     $message = $this->input->post('message');

     $this->load->library('email',$config); 
     $this->email->set_newline("\r\n");

     $this->email->from($from_email); 
     $this->email->to($to_email);
     $this->email->subject($subject); 
     $this->email->message($message);

     $this->email->send();       
  }     
  • Have you done any troubleshooting? Looked at the logs? Tried any other settings? – Sparky Jul 19 '16 at 01:56
  • If your using localhost you may need to configure your php.ini file and sendmail.ini https://www.youtube.com/watch?v=TO7MfDcM-Ho –  Jul 19 '16 at 02:56

2 Answers2

1

Try this and check logs of your server:

$config = array(
    'protocol' => 'smtp',
    'smtp_host' => 'smtp.gmail.com',
    'smtp_port' => 465, // or 587
    'smtp_user' => 'xxx@gmail.com',
    'smtp_pass' => 'xxx',
    'charset' => 'utf-8',
    'mailtype' => 'html'
);

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

$this->email->from($from_email); 
$this->email->to($to_email);
$this->email->subject($subject); 
$this->email->message($message);

if (!$this->email->send()) {
    echo $this->email->print_debugger();
}

For more examples look at this question.

blues911
  • 840
  • 8
  • 9
0

you can try the below code

        $this->load->library('email');          
        $config['protocol'] = "smtp";
        $config['smtp_host'] = 'mail.domain.com'; //smtp host name
        $config['smtp_port'] = '587'; //smtp port 
        $config['smtp_user'] = 'mail@domain.com'; //smtp username
        $config['smtp_pass'] = '12345'; //smtp password
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['newline'] = "\r\n";
        $config['wordwrap'] = TRUE;
        $this->email->initialize($config);          
        $this->email->from('from@gmail.com', 'website.com');
        $this->email->to('to@gmail.com');             
        $msg="This is test message";
        $this->email->subject('Test Subject');
        $this->email->message($msg);
        $this->email->send();