Codeigniter SMTP Unable to Connect

I am using Codeigniter 3 and have a simple contact form on my website. This contact form works fine on my local XAMPP environment, but not on my shared web hosting (BT).

I can't figure out what the problem is, I was in contact with my support and apparently if an email account can send and receive email via email clients (which it can) they don't offer any further support: /

I can sign in to Office365 to send and receive emails using this account. Smpt settings in Office365:

Server name: smtp.office365.com
Port: 587
Encryption method: STARTTLS

      

My current code looks like this:

    $config['protocol']     = 'smtp';
    $config['smtp_host']    = 'smtp.office365.com'; // also tried tls://smtp.office365.com 
    $config['smtp_port']    = '587';
    $config['smtp_user']    = 'MyEmail@btconnect.com'; 
    $config['smtp_pass']    = 'MyPass'; 
    $config['smtp_crypto'] = 'tls';
    $config['mailtype']     = 'html';
    $config['wordwrap']     = TRUE;
    $config['charset']  = 'iso-8859-1';
    $config['newline']  = "\r\n"; 

      

An email is sent to localhost and no problem. On the Live web host, I get the following error:

Message: fsockopen (): Unable to connect to smtp.office365.com:587 (Connection timed out)

I read that the problem might be because OpenSSL is not enabled, however the web host has confirmed that it is enabled. I also checked the loaded extensions with the following code:

    echo "<pre>";
    print_r(get_loaded_extensions());
    echo "</pre>";

      

This returns;

Array
(
    [0] => Core
    [1] => date
    [2] => ereg
    [3] => libxml
    [4] => openssl
    [5] => pcre
    etc
    etc
)

      

I have verified that I can connect to the SMTP server using the following code:

$fp = fsockopen('tcp://smtp.office365.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
var_dump($fp, $errno, $errstr);
fclose($fp);

      

On my localhost, I get the following message:

220 VI1PR0602CA0001.outlook.office365.com Microsoft ESMTP MAIL Service Ready Monday, June 19, 2017 10:19:10 +0000 resource (55) type (stream) int (0) string (0) ""

On a real server, I get this:

Message: fsockopen (): Unable to connect to tcp: //smtp.office365.com: 587 (Connection timed out)

I tried Gmail smtp, again this works locally, but not on the remote website.

Is there anything else I should try or ask my web host to check? I am currently out of ideas.

Any help is appreciated.

+3


source to share


1 answer


I don't know if this will work in your case, but I have the same problem. it's working on my local development using manor, but its bug in hostgator. what i did to fix it i change the protocol value to mail.

try to change your code:

$config['protocol']     = 'smtp';

      



:

$config['protocol']     = 'mail';

      

+5


source







All Articles