0

I have the following email.php file:

<?php
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "rn";
?>

And in the controller I have the next:

$this->load->library('email');
$this->email->from('agro@agro.com', 'Agro');
$this->email->to($Nom_usu);
$this->email->subject('Confirmar registro');
$this->email->message('<a href="'.base_url().'Cregistro/confirm/'.$Nom_usu.'">Click Aqui</a>');
$this->email->send();

However, when I try to send an email, I get the next answer:

string(992) "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Mon, 1 Oct 2018 00:33:26 -0400
From: "Agro" <agro@agro.com>
Return-Path: <agro@agro.com>
Reply-To: <agro@agro.com>
X-Sender: agro@agro.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5bb1a396c22bb@agro.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5bb1a396c22cb"
=?UTF-8?Q?Confirmar=20registro?=
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_5bb1a396c22cb
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Click Aqui


--B_ALT_5bb1a396c22cb
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

=3Ca href=3D=22http://localhost/WebAgro2/Cregistro/confirm/juan.rodriguez=
=40ideasfractal.com=22=3EClick Aqui=3C/a=3E

--B_ALT_5bb1a396c22cb--
"

I have followed a lot of the post with this similar issue, but it seems that nothing works. I'm using localhost in linux.

Any help is appreciated!

JuanF
  • 756
  • 1
  • 6
  • 12
  • 1
    Possible duplicate of [CodeIgniter unable to send email using PHP mail()](https://stackoverflow.com/questions/3859958/codeigniter-unable-to-send-email-using-php-mail) – Sinto Oct 01 '18 at 04:41
  • If you don't have a local email server setup, then you can send it suing `smtp` using a external email account such as GMail. It forwards the email to your email account and then sends it from their. It's a bit easier then setting up and maintaining an email server. – ArtisticPhoenix Oct 01 '18 at 04:44
  • @Sinto I have followed the solutions in that post without any result. I have tried the smtp too, but with the same error message – JuanF Oct 01 '18 at 04:52
  • SMTP can be tricky, for GMAIL you have to use SSL and a certain port for it to work (I forget which one). But I use Gmail SMTP with CI 2.x on my local dev server at work and it does work. – ArtisticPhoenix Oct 01 '18 at 05:20

2 Answers2

1

there are 2 ways to test email on localhost one is mailcatcher you need to install mailcatcher on you development machine super simple smtp server, other is mailtrap i prefer mailtrap no need to install anything, create an account on mailtrap and you are ready to test your emails on localhost once you login you can get your account setting from mailtrap

$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['newline'] = "rn";

if(ENVIRONMENT == 'development'){

$dev_config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'smtp.mailtrap.io',
  'smtp_port' => 2525,
  'smtp_user' => 'smtp_user_from_your_mailtrap',
  'smtp_pass' => 'smtp_pass_from_your_mailtrap',
  'crlf' => "\r\n",
  'newline' => "\r\n"
);

$config = array_merge($config, $dev_config);

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

and happy local email testing.

umefarooq
  • 4,540
  • 1
  • 29
  • 38
0

Make sure you have set at least these four configuration preferences in your config email.php file

$config['protocol'] = 'sendmail';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
Pyae Phyo Aung
  • 270
  • 1
  • 4
  • 17