Last active
November 4, 2022 06:07
-
-
Save WebFikirleri/b2692cb08a35163d7d5fd695811776b3 to your computer and use it in GitHub Desktop.
Codeigniter Send Email Example (Gmail Example)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$config['useragent'] = 'CodeIgniter'; | |
$config['protocol'] = 'smtp'; | |
$config['mailpath'] = '/usr/sbin/sendmail'; | |
$config['smtp_crypto'] = 'ssl'; | |
$config['smtp_host'] = 'smtp.gmail.com'; | |
$config['smtp_user'] = '[email protected]'; | |
$config['smtp_pass'] = 'youremailpassword'; | |
$config['smtp_port'] = 465; | |
$config['smtp_timeout'] = 5; | |
$config['smtp_keepalive'] = FALSE; | |
$config['wordwrap'] = TRUE; | |
$config['wrapchars'] = 80; | |
$config['mailtype'] = 'html'; | |
$config['charset'] = 'utf-8'; | |
$config['validate'] = FALSE; | |
$config['priority'] = 3; | |
$config['crlf'] = "\r\n"; | |
$config['newline'] = "\r\n"; | |
$config['bcc_batch_mode'] = FALSE; | |
$config['bcc_batch_size'] = 200; | |
$config['dsn'] = FALSE; | |
$config['sender_name'] = 'Your Cool Sender Name'; | |
$config['reply_to'] = '[email protected]'; | |
/* End of file email.php */ | |
/* Location: ./application/config/email.php */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class MY_Controller extends CI_Controller { | |
public function _send_mail($to,$subjet,$message,$cc=null) | |
{ | |
$this->load->library('email'); | |
$this->email->from(config_item('smtp_user'), config_item('sender_name')); | |
$this->email->to($to); | |
if ($cc !== null) $this->email->cc($cc); | |
$this->email->reply_to(config_item('reply_to')); | |
$this->email->set_alt_message('You need to HTML supported web browser or email client to display this email'); | |
$this->email->subject($subject); | |
$this->email->message($message); | |
if ($this->email->send(FALSE)) return true; | |
else { return $this->email->print_debugger(); $this->email->clear(TRUE); } | |
} | |
} | |
/* End of file MY_Controller.php */ | |
/* Location: ./application/core/MY_Controller.php */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Myawesomecontroller extends MY_Controller { | |
public function index() { | |
$html_message = '<h1>Hello</h1>'; | |
$is_sended = $this->_send_mail('[email protected]','Email Test', $message, '[email protected]'); | |
if ($is_sended !== TRUE) die($is_sended); | |
} | |
} | |
/* End of file Myawesomecontroller.php */ | |
/* Location: ./application/controllers/Myawesomecontroller.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment