Welcome Guest, Not a member yet? Register   Sign In
Sending email using smtp doesn't work
#1

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();
    }

Reply
#2

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(); 
Reply
#3

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';
Reply
#4

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB