CodeIgniter Forums
Sending email using smtp doesn't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Sending email using smtp doesn't work (/thread-76088.html)



Sending email using smtp doesn't work - muuucho - 04-13-2020

The following code doesn't work (no email is received) 
PHP Code:
<?php namespace App\Controllers;

class 
Email extends BaseController
{
    public function 
index()
    {
        $config['protocol'] = 'smtp';
        $config['charset']  'iso-8859-1';
        $config['wordWrap'] = true;
        $config['SMTPHost'] = 'ssl://smtp.gmail.com';
        $config['SMTPUser'] = '[email protected]';
        $config['SMTPPass'] = 'xxx';
        $config['SMTPCrypto'] = 'ssl'// tls or ssl
        $config['SMTPPort'] = 465// tls:587  ssl:465
        $config['mailType'] = 'html';

        $email = \Config\Services::email();
        $email->initialize($config); // Use the config above

        $email->setFrom('[email protected]''xxx');
        $email->setTo('[email protected]');
        $email->setSubject('Email Test');
        $email->setMessage('Testing the email class.');
        $email->send();
    }




RE: Sending email using smtp doesn't work - muuucho - 04-14-2020

I have also tried sendgrid without success:
PHP Code:
$config['protocol']         'smtp';
        $config['smtpHost']        'smtp.sendgrid.net';
        $config['smtpPort']        587;
        $config['smtpUser']        'apikey';
        $config['smtpPass']        'my_key';
        $config['charset']          'utf-8';
        $config['mailType']         'html';
        $config['SMTPCrypto'] = 'tls'// tls or ssl

       

        $email 
= \Config\Services::email();
        $email->initialize($config); // Use the config above

        $email->setFrom('[email protected]''xxx');
        $email->setTo('[email protected]');
        $email->setSubject('Email Test');
        $email->setMessage('Testing the email class.');
        $email->send(); 



RE: Sending email using smtp doesn't work - elephpantech - 04-14-2020

Works fine with:

public $fromEmail = '[email protected]';
public $protocol = 'smtp';
public $SMTPHost = 'smtp.gmail.com';
public $SMTPUser = '[email protected]';
public $SMTPPass = '********';
public $SMTPPort = 587;
public $SMTPCrypto = 'tls';


RE: Sending email using smtp doesn't work - muuucho - 04-15-2020

(04-14-2020, 06:27 AM)elephpantech Wrote: Works fine with:

public $fromEmail = '[email protected]';
public $protocol = 'smtp';
public $SMTPHost = 'smtp.gmail.com';
public $SMTPUser = '[email protected]';
public $SMTPPass = '********';
public $SMTPPort = 587;
public $SMTPCrypto = 'tls';
Thanks, that works. Is was wrong in the setting of port/crypto and host. I will now start to test using Sendgrid or another email service.