3
votes

Edited: Im trying to send an email using codeigniter's library. Whenever I call the $this->email->send() function it returns

Warning: include(C:\xampp\htdocs\psems\application\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269

Warning: include(): Failed opening 'C:\xampp\htdocs\psems\application\views\errors\html\error_php.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\psems\system\core\Exceptions.php on line 269

This is the code I have so far

 $config = array();
    $config['useragent']           = "CodeIgniter";
    $config['mailpath']            = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
    $config['protocol']            = "smtp";
    $config['smtp_host']           = "localhost";
    $config['smtp_port']           = "25";
    $config['mailtype'] = 'html';
    $config['charset']  = 'utf-8';
    $config['newline']  = "\r\n";
    $config['wordwrap'] = TRUE;

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

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

    $this->email->from('[email protected]', 'harold decapia');
    $this->email->to('[email protected]');

    $this->email->subject('Тест Email');
    $this->email->message('Hello World');

    $this->email->send(); //I tried commenting this out and there was no error returned

I'm confused as to why it returns an error just by calling the send method. Do I have to configure something first? I'm thinking I'm missing a tiny bit of info here :(

Also, is there any way for me to know what error it returns specifically? Thank you in advance

1
try echo $this->email->print_debugger(); - Amit Chauhan
tried that and it said "The following SMTP error was encountered: 10061 No connection could be made because the target machine actively refused it. Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. " - Harold Decapia
have you tried php mailer lib for smtp - Amit Chauhan
not yet. i actually have that in mind but i want this to work :( - Harold Decapia

1 Answers

0
votes

The error as far as I can see it's coming because you're trying to send an email with SMTP on a server without and actual FTP server (Happens a lot with local servers).

I'm going to suggest a free service like Mailgun to use as an SMTP server while you're developing.

Also if you're going to use SMTP protocol, you'll need to use an User and Password to authenticate on the SMTP server (Mailgun will provide you with that too).

Here it's a sample of the new configurations for the SMTP server/authentication, remember you need to adjust to the information the Mailgun website will give you on your account.

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.mailgun.org';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '30';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['mailtype'] = 'html';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";

:)