Sending email through G suite in Codeigniter
1. Load email library
$this->load->library('email');
2. SMTP & mail configuration
$config = array(
'protocol' => 'mail',
'smtp_host' => 'ssl://smtp-relay.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'YourGsuiteEmail',
'smtp_pass' => 'YourGsuitePassword',
'mailtype' => 'html',
'charset' =>'utf-8'
);
$this->load->library('email', $config);
$this->email->initialize($config);
$this->email->from($email);
$this->email->reply_to($to);
$this->email->to($to);
$this->email->to($$this->email->subject($subject);
3. Email content
$content = 'Name: '.$name.'<br>'.
'E-mail: '.$email.'<br>'.
'Message : '.$message;
$this->email->message($content);
if($this->email->send()) {
$this->session->set_flashdata('success', 'Thanks for contacting us, we will revert to you as soon as possible.');
} else {
$this->session->set_flashdata('success', 'Connection Error');
}
if you want to receive email from web application to G suite email, set recipient address function to() as follows:
$to = 'YourGsuiteEmai.test-google-a.com';
Or
$to = 'YourGsuiteEmail';
Comments
Post a Comment