What i need: I need to send a email from Codeigniter with Sendgrid API key.
I have showed the example below of sending email using SMTP details and username and password in codeigniter.
Example:
Create a file with name "email.php" in application/config folder and paste the below code in it.
/* application/config/email.php */
<?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'] = 'yourusername';
$config['smtp_pass'] = 'yourpassword';
?>
In Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->library('email');
$this->email->from('[email protected]', 'John');
$this->email->to('[email protected]');
$this->email->subject('Test Email using SendGrid');
$this->email->message('This email was delivered by your friends at SendGrid');
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('welcome_message');
}
}
?>
But i need to send mail through the API key. Is there any possibilities to do.
Thanks