CodeIgniter comes with an email sending library built in. See more information on how to use CodeIgniter with SendGrid.
It is important to use the correct end of lines using "crlf" => "\r\n" and "newline" => "\r\n".
1<?php2$this->load->library('email');34$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));1314$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();2122echo $this->email->print_debugger();23?>