1
votes

Hello i have a probleme with code igniter mail send here is my code

function __construct()
{
    parent::__construct();
    $this->load->library('email');


}

    function index()
    {
        $this->load->library('email');
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'smtp.mailtrap.io',
            'smtp_port' => 2525,
            'smtp_user' => 'edf81f6d31af91',
            'smtp_pass' => '6d824154999158',
            'crlf' => "\r\n",
            'newline' => "\r\n"
        );
        $this->email->initialize($config);

        $this->email->from('[email protected]', 'Your Name');
        $this->email->to('[email protected]');


        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');

        $this->email->send();



    }

and when i execute this code i get this error

A PHP Error was encountered Severity: Warning

Message: fsockopen():

Filename: libraries/Email.php

Line Number: 2055

Backtrace:

File: C:\xampp\htdocs\ctmprod\application\libraries\Email.php Line: 2055 Function: fsockopen

File: C:\xampp\htdocs\ctmprod\application\libraries\Email.php Line: 1950 Function: _smtp_connect

File: C:\xampp\htdocs\ctmprod\application\libraries\Email.php Line: 1825 Function: _send_with_smtp

File: C:\xampp\htdocs\ctmprod\application\libraries\Email.php Line: 1715 Function: _spool_email

File: C:\xampp\htdocs\ctmprod\application\controllers\email.php Line: 51 Function: send

File: C:\xampp\htdocs\ctmprod\index.php Line: 315 Function: require_once

1
I hope those aren't your real SMTP credentials. And is that really the entirety of the warning? It seems unlikely it would be so brief. - ADyson
using mail trap fake smtp dump don't worry and yes that's the wole error - Mehdi Ammar
Ok. I would expect there to be some more content on the warning after Message: fsockopen(): ? - ADyson
no that's the whole message sir - Mehdi Ammar
Remove $this->load->library('email'); from index() method. It is already loaded in constructor. - Tpojka

1 Answers

0
votes
function sesnd_mail()
{
    $this->load->library('email');
    $config = array();
    $config['useragent'] = "CodeIgniter";
    $config['mailpath']  = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
    $config['protocol']  = "smtp";
    $config['smtp_host'] = "smtp.sendgrid.net";
    $config['smtp_user'] = "username";
    $config['smtp_pass'] = "password ";        
    $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->subject('TEST SUBJECT');
    $this->email->message("THIS IS A TEST MESSAGE");
    $this->email->from( "[email protected]"  );        
    $this->email->to("[email protected]");
    if($this->email->send())
    {
    echo "success";
    }
    else
    {
    echo $this->email->print_debugger();
    }   
}