Welcome Guest, Not a member yet? Register   Sign In
email library
#1

email function does not work,

$this->load->library('email');
$this->email->from('[email protected]', 'Admin');
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if($this->email->send()){
echo 'Email enviado';
}
else{
show_error($this->email->print_debugger());
}

the error is
"
An Error Was Encountered
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
"

what do i have to configure?
thanks
Reply
#2

(This post was last modified: 08-31-2015, 12:17 AM by davidgv88.)

Hi isideas.

Have you a shared server?

Typically shared servers do not allow you to use the mail function. You can contact with Customer Service of your Hosting.

With your method the email will go directly to SPAM. You must use SMTP

You can do this before contact with the Customer Service:



Code:
$this->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "[email protected]";
$config['smtp_pass'] = "YOUR_PASSWORD";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

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

$this->email->from('[email protected]', 'Admin');
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if($this->email->send()){
echo 'Email enviado';
}
else{
show_error($this->email->print_debugger());
}
Reply
#3

Hi, I used your code, I changed the password...
I am using DigitalOcean Droplet with Lamp 14.04 as server

Do I have to do another configuration in php.ini or other file?

/*this is the error message*/

An Error Was Encountered

220 smtp.gmail.com ESMTP 65sm8618367qkq.41 - gsmtp

hello: 250-smtp.gmail.com at your service, [45.55.196.47]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 65sm8618367qkq.41 - gsmtp
from: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
to: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
data: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 65sm8618367qkq.41 - gsmtp
502 5.5.1 Unrecognized command. 65sm8618367qkq.41 - gsmtp
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. 65sm8618367qkq.41 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Mon, 31 Aug 2015 07:33:35 -0400
From: "Admin" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Subject: =?utf-8?Q?Email_Test?=
Reply-To: "[email protected]" <[email protected]>
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_55e43b8fcf60c"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_55e43b8fcf60c
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Testing the email class.


--B_ALT_55e43b8fcf60c
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Testing the email class.

--B_ALT_55e43b8fcf60c--
Reply
#4

Assuming you are sure in gmail 2factor auth is disabled, weak apps enabled etc. there could be an other problem. Test send an email via telnet / openssl s_client.

I found that "AUTH LOGIN" (codeiginter default) does not work, but AUTH PLAIN does. (Strange since ehlo command states AUTH LOGIN support).


Therefore I decided to add PLAIN auth to codiginter and AUTH LOGIN as fallback. I did extend the Email library (via MY_Email class) to overwrite the login function:

 
PHP Code:
protected function _smtp_authenticate()
  {
    if ( ! $this->_smtp_auth)
    {
      return TRUE;
    }

    if ($this->smtp_user === '' && $this->smtp_pass === '')
    {
      $this->_set_error_message('lang:email_no_smtp_unpw');
      return FALSE;
    }

    $this->_send_data('AUTH PLAIN '.base64_encode("\000".$this->smtp_user."\000".$this->smtp_pass));

    $reply $this->_get_smtp_data();

    if (strpos($reply'503') === 0 // Already authenticated
    {
      return TRUE;
    }
    elseif (strpos($reply'235') === 0)
    {
      return TRUE;
    }
    $this->_set_error_message('lang:email_failed_smtp_login'$reply);

    $this->_send_data('AUTH LOGIN');

    $reply $this->_get_smtp_data();

    if (strpos($reply'503') === 0 // Already authenticated
    {
      return TRUE;
    }
    elseif (strpos($reply'334') !== 0)
    {
      $this->_set_error_message('lang:email_failed_smtp_login'$reply);
      return FALSE;
    }

    $this->_send_data(base64_encode($this->smtp_user));

    $reply $this->_get_smtp_data();

    if (strpos($reply'334') !== 0)
    {
      $this->_set_error_message('lang:email_smtp_auth_un'$reply);
      return FALSE;
    }

    $this->_send_data(base64_encode($this->smtp_pass));

    $reply $this->_get_smtp_data();

    if (strpos($reply'235') !== 0)
    {
      $this->_set_error_message('lang:email_smtp_auth_pw'$reply);
      return FALSE;
    }

    return TRUE;
  

The Codeiginter smtp protocol implementation is very basic. What I did is more like a quick fix than a perfect solution. But it worked.


PHP Code:
 $config = array (
 
   'protocol'   => "smtp",
 
   'smtp_host'  => "ssl://smtp.gmail.com",
 
   'smtp_port'  => 465,
 
   'smtp_user'  => "",
 
   'smtp_pass'  => "",
 
   'useragent'  => "",
 
   'mailtype'   => "html",
 
   'charset'    => "utf-8",
 
   'from_addr'  => "",
 
   'from_name'  => "",
 
   'newline'    => "\r\n",
 ); 

 Using single quotes for newline didn't work, therefore my email config (with blank fields filled by my login data). 

Hope this helps.
Reply
#5

(This post was last modified: 10-16-2015, 12:21 PM by CroNiX.)

Also, make sure you are allowing smtp connections from within your gmail account settings.
Reply
#6

Also some servers do not allow sending and receiving emails from the same email address.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB