public
Last active

SendGrid + CodeIgniter

  • Download Gist
email.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php
 
/* application/config/email.php */
 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
/*
|--------------------------------------------------------------------------
| SendGrid Setup
|--------------------------------------------------------------------------
|
| All we have to do is configure CodeIgniter to send using the SendGrid
| SMTP relay:
*/
$config['protocol'] = 'smtp';
$config['smtp_port'] = '587';
$config['smtp_host'] = 'smtp.sendgrid.net';
$config['smtp_user'] = 'your_sendgrid_username';
$config['smtp_pass'] = 'your_sendgrid_password';
welcome.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
 
/* application/controllers/welcome.php */
 
public function index()
{
$this->load->library('email');
 
$this->email->from('john.doe@example.com', 'John');
$this->email->to('jane.doe@example.com');
$this->email->subject('Test Email using SendGrid');
$this->email->message('This email was delivered by your friends at SendGrid');
 
$this->email->send();
 
$this->load->view('welcome_message');
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.