Skip to contentSkip to navigationSkip to topbar
Page tools
Looking for more inspiration?Visit the

CodeIgniter


To send email with CodeIgniter and SendGrid, configure CodeIgniter's built-in email library to use SendGrid's SMTP relay. See the CodeIgniter email library documentation(link takes you to an external page) for more information.

(information)

Info

Use the correct end of lines with "crlf" => "\r\n" and "newline" => "\r\n".

1
<?php
2
$this->load->library('email');
3
4
$this->email->initialize(array(
5
'protocol' => 'smtp',
6
'smtp_host' => 'smtp.sendgrid.net',
7
'smtp_user' => 'apikey',
8
'smtp_pass' => 'sendgridapikey',
9
'smtp_port' => 587,
10
'crlf' => "\r\n",
11
'newline' => "\r\n"
12
));
13
14
$this->email->from('your@example.com', 'Your Name');
15
$this->email->to('someoneexampexample@example.com');
16
$this->email->cc('another@another-example.com');
17
$this->email->bcc('them@their-example.com');
18
$this->email->subject('Email Test');
19
$this->email->message('Testing the email class.');
20
$this->email->send();
21
22
echo $this->email->print_debugger();
23
?>