Log In

This guide provides a simple script to send an email usingĀ Email Class.

Step 1

Please change the following variables in this guide:

Sender Name: the sender’s name.

sender@example.com: the sender’s email address.

Recipient Name: the recipient’s name.

recipient@example.com: the recipient’s email address.

USERNAME: your SMTP username.

PASSWORD: your SMTP password.

Step 2

Create a file application/config/email.php with the following content:

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.smtp2go.com';
$config['smtp_port'] = '2525'; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$config['smtp_crypto'] = 'tls';
$config['smtp_user'] = 'USERNAME';
$config['smtp_pass'] = 'PASSWORD';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "rn";

Step 3

Add the following code in your controller:

$this->email->from('sender@example.com', 'Sender Name');
$this->email->to('recipient@example.com','Recipient Name');
$this->email->subject('Your Subject');
$this->email->message('Your Message');
echo 'Message has been sent.';
}catch(Exception $e){
echo $e->getMessage();

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.