tony amprou
tony amprou

Reputation: 21

Smtp Codeigniter 3

In order to train me on codeigniter I decided to set up an application protected by login password. In case of password lost I have a function of confirmation by mail. but there...

220 smtp.gmail.com ESMTP j39-v6sm10096073wre.44 - gsmtp

hello: 250-smtp.gmail.com at your service, [86.236.5.51]

250-SIZE 35882577

250-8BITMIME

250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH

250-ENHANCEDSTATUSCODES

250-PIPELINING

250-CHUNKING

250 SMTPUTF8

from: 250 2.1.0 OK j39-v6sm10096073wre.44 - gsmtp

to: 250 2.1.5 OK j39-v6sm10096073wre.44 - gsmtp

data: 354 Go ahead j39-v6sm10096073wre.44 - gsmtp

quit:

L'erreur SMTP suivante s'est produite :

L'erreur SMTP suivante s'est produite :

Impossible d'envoyer des emails avec la méthode SMTP de PHP. Votre serveur ne doit pas être configuré pour pouvoir utiliser cette méthode.

Date: Sun, 19 Aug 2018 08:51:39 +0000

From:

Return-Path:

To: [email protected]

Subject: =?UTF-8?Q?\r=20test?=

Reply-To:

User-Agent: CodeIgniter

X-Sender: [email protected]

X-Mailer: CodeIgniter

X-Priority: 3 (Normal)

Message-ID: <[email protected]>

Mime-Version: 1.0

Content-Type: text/plain; charset=UTF-8

Content-Transfer-Encoding: 8bit

Bonjour

I do not understand the mistake I could make. Here is my code.

public function oubli() 
	{
	$this->load->helper("form");
	$this->load->library('form_validation');
		$this->form_validation->set_rules('mail','mail','trim|required');
		if($this->form_validation->run() ==false) 
		{
			$this->load->view('login/oubli');
		}
		else
		{	
		$mail = $this->input->post('mail');
		$this->auth_user->oubli_pass($mail);
		$nombre = $this->auth_user->nombre;
			if($nombre == '1') 
			{
        	$this->load->library('email');
        	$this->config->load('email', TRUE);
        	$this->email->initialize($this->config->item('email'));
        	$this->email->from('[email protected]');
        	$this->email->to($this->input->post('mail'));
       		$this->email->subject('test');
        	$this->email->message('Bonjour');
        		if($this->email->send())
        		{
        		$data['result_class'] = "alert-success";
        		$data['result_message'] ="Un email de reinitialisation vient de vous etre envoyé";
				}
				else
				{
				$data['result_class'] = "alert-danger";
            	$data['result_message'] = "Votre message n'a pas pu être envoyé. Nous mettons tout en oeuvre pour résoudre le problème.";
            	$data['result_message'] .= "<pre>\n";
            	$data['result_message'] .= $this->email->print_debugger();
            	$data['result_message'] .= "</pre>\n";
            	$this->email->clear();	
				}
			$this->load->view('login/oubli_result', $data);
			}
			else
			{
				$data['mail_error'] = "L'adresse mail est inconnu";
				$this->load->view('login/oubli', $data); 
			}

		}
	}

And my config files ...

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$config['protocol']  = "smtp";
$config['smtp_host'] = "smtp.gmail.com";
$config['smtp_user'] = "[email protected]";
$config['smtp_pass'] = "MON MOT DE PASSE";
$config['smtp_port'] = '465';
$config['charset']   = 'utf-8';
$config['newline']   = '\r\n';
$config['crlf']		 = '\n';
$config['mailtype']	 = 'text';
$config['starttls']  =  'true';
$config['smtp_crypto'] = "ssl";
$config['ssl'] = "ssl";

Upvotes: 2

Views: 1747

Answers (2)

tony amprou
tony amprou

Reputation: 21

Problem solved.

I added in my controller the line "$ this-> email-> set_newline (" \ r \ n ");".

The email is sent well. That said I do not understand why this little command line solve my problem ...

$ this-> email-> set_newline (" \ r \ n ");".

Upvotes: 0

Kirtee
Kirtee

Reputation: 141

Make sure that in your gmail you have enabled "Allow less secure app" settings. and check your recent login activity in gmail there you may need to allow access for your server. After this things test it again if it still doesn't work got to this URL https://accounts.google.com/b/0/displayunlockcaptcha click "continue" and test it again. Now it should work

Upvotes: 1

Related Questions