简体   繁体   English

从网站在CodeIgniter中使用SMTP gmail发送电子邮件

[英]Sending Email using SMTP gmail in CodeIgniter from website

I'm stuck on my problem to send email with codeigniter. 我遇到了问题,无法通过codeigniter发送电子邮件。

I've already done successful sending gmail, but the problem is the recipient and the sender are the same. 我已经成功发送了gmail,但是问题是收件人和发件人相同。 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 这是我的观点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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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