简体   繁体   中英

Sending Email using SMTP gmail in CodeIgniter from website

I'm stuck on my problem to send email with codeigniter.

I've already done successful sending gmail, but the problem is the recipient and the sender are the same. I want this email received to me from sender in website,

There is my Controller :

public function index(){        
    $this->sendEmail(); 
    $this->load->view('content_contact');
}
public function sendEmail(){
    $this->load->helper(array('form', 'url'));
    $this->load->library('email');

    //konfigurasi email
    $config = array();
    $config['charset'] = 'utf-8';
    $config['useragent'] = 'Codeigniter';
    $config['protocol']= "smtp";
    $config['mailtype']= "html";
    $config['smtp_host']= "ssl://smtp.gmail.com";
    $config['smtp_port']= 465;
    $config['smtp_timeout']= "5";
    $config['smtp_user']= "my_email$gmail.com";
    $config['smtp_pass']= "my_pass";            
    $config['crlf']="\r\n";
    $config['newline']="\r\n";

    $config['wordwrap'] = TRUE;
    $this->load->view('content_contact');

    $this->email->initialize($config);
    $this->email->from($this->input->post('from'));
    $this->email->to("my_email@gmail.com");
    $this->email->subject($this->input->post('subject'));
    $this->email->message($this->input->post('isi'));

    if($this->email->send()){
        echo "pengiriman email Success";
    }
    else{
        echo "pengiriman email Failed";
    }

}

And This is my View : content_contact.php content_contact.php

use below mentioned solution

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'my_email@gmail.com',
    'smtp_pass' => 'yourpassword',
    'mailtype'  => 'html', 
    'charset'   => 'utf-8',
    'wordwrap'  => TRUE
);
$this->load->library('email', $config);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM