1
votes

For some reason CodeIgniter is not connecting to my SMTP server, anyone have any problems surrounding this?

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.netregistry.com.au';
$config['smtp_port'] = '465';

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to smtp.netregistry.com.au:465 (php_network_getaddresses: getaddrinfo failed: Name or service not known)

Filename: libraries/Email.php

Line Number: 1689

Should I be using the SSL or non-SSL port? (I've tried both; no dice)

Is there a way of explicitly telling CI to use SSL or not?

Am I doing anything blaringly wrong here?

Thanks

4
Do you ping to host ? ping smtp.netregistry.com.au - php_network_getaddresses: getaddrinfo failed: Name or service not known - seems like addr not resolved - Sergey
Silly mistake on my account, I didn't even think to check that the smtp server was on the same domain as the pop server. .net not .com.au - thanks. - Zen

4 Answers

1
votes

The smtp server was actually incorrect.

0
votes

From the error, it said "getaddrinfo failed: Name or service not known".
And the function php_network_getaddresses shoots the error.

That might means your SMTP server is behind your company gateway, or is a private server.

So, that results in fsockopen() doesn't seem to find your SMTP server.

Try to run your code again in your company, that should work then.

0
votes

You could try putting ssl: in the host address:

$config['smtp_host'] = 'ssl://smtp.netregistry.com.au';
$config['smtp_port'] = '465';

Quite often smtp hosts have security in place that prevents this kind of use. Have you tried using a gmail account? That does work for me, here is how I use it:

function send_email($attributes) {

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

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

    $config['protocol'] = 'smtp';
    $config['smtp_host'] = 'ssl://smtp.googlemail.com';
    $config['smtp_port'] = '465';
    $config['smtp_user'] = '[email protected]';
    $config['smtp_from_name'] = 'FROM NAME';
    $config['smtp_pass'] = 'XXX';
    $config['wordwrap'] = TRUE;
    $config['newline'] = "\r\n";
    $config['mailtype'] = 'html';                       

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

    $this->email->from($config['smtp_user'], $config['smtp_from_name']);
    $this->email->to($attributes['to']);
    $this->email->cc($attributes['cc']);
    $this->email->bcc($attributes['cc']);
    $this->email->subject($attributes['subject']);

    $this->email->message($attributes['message']);

    if($this->email->send()) {
        return true;        
    } else {
        return false;
    }       

}

0
votes

there will be system/libraries/Email.php file. default port will be 25 .please also add smtp_host as localhost there like this..

var $smtp_host      = "localhost";       
var $smtp_port      = "25";