Question

I am having the following code

            ini_set("SMTP","ssl://smtp.gmail.com");
            ini_set("smtp_port","587");

            $config['protocol'] = 'smtp';
            $config['smtp_host'] = 'smtp.gmail.com';
            $config['smtp_port'] = '587';
            $config['_smtp_auth']=TRUE;
            $config['smtp_user'] = 'sender@gmail.com';
            $config['smtp_pass'] = 'password';
            $config['smtp_timeout'] = '60';
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = "html";

            $this->email->initialize($config);

            $this->email->from('sender@gmail.com', 'Sender');
            $this->email->to('receiver@gmail.com');

            $this->email->subject('This is my subject');
            $this->email->message('This is the content of my message');

            if ( ! $this->email->send())
            {
                show_error($this->email->print_debugger());
            }
            else
            {
                echo('DONE');
            }

But when the code executes, I am getting the following error

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. qd9sm8462833pbb.31

I have used

$this->load->library('email');

in my controller's constructor. But I am unable to send email from localhost. What can be the solution to send email? What changes do I need to make?

Was it helpful?

Solution

I think you should set "Enable IMAP" option in your Gmail account.

It is in the Mail options.

And change your port to 465 ...

$config['smtp_port'] = '587';

to

$config['smtp_port'] = '465';

OTHER TIPS

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';

Add:

$config['smtp_crypto'] = 'tls'; // or html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top