简体   繁体   English

Codeigniter SMTP无法连接

[英]Codeigniter SMTP Unable to Connect

I'm using Codeigniter 3 and have a simple contact form on my website. 我正在使用Codeigniter 3并在我的网站上有一个简单的联系表格。 This contact form works perfectly on my localhost XAMPP environment, but not on my shared web hosting (BT). 此联系表单在我的localhost XAMPP环境中完美运行,但不在我的共享Web托管(BT)上。

I can't fugire out what the issue is, I've been in contact with their support and apparently if the email account is able to send and receive emails via email clients (which it can) they don't offer any additional support :/ 我不能不知道问题是什么,我一直在接触他们的支持,显然如果电子邮件帐户能够通过电子邮件客户端发送和接收电子邮件(它可以),他们不提供任何额外的支持: /

I am able to login to Office365 to send and receive emails using this account. 我可以使用此帐户登录Office365以发送和接收电子邮件。 The smpt settings in Office365 are; Office365中的smpt设置是;

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

My current code is as follows; 我目前的代码如下;

    $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"; 

In localhost the email sends and there are no issues. 在localhost中,电子邮件发送并且没有问题。 On the live web host I receive the following error; 在实时Web主机上,我收到以下错误;

Message: fsockopen(): unable to connect to smtp.office365.com:587 (Connection timed out) 消息:fsockopen():无法连接到smtp.office365.com:587(连接超时)

I've read that the issue could be related to OpenSSL not being enabled, however the web host has confirmed it is enabled. 我已经读过这个问题可能与OpenSSL没有启用有关,但Web主机已经确认它已启用。 I've also checked the loaded extensions using 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've checked that I'm able to connect to the smtp server using the following code; 我已经检查过我能够使用以下代码连接到smtp服务器;

$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 receive the following message; 在我的本地主机上,我收到以下消息;

220 VI1PR0602CA0001.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 19 Jun 2017 10:19:10 +0000 resource(55) of type (stream) int(0) string(0) "" 220 VI1PR0602CA0001.outlook.office365.com Microsoft ESMTP MAIL服务就绪时间2017年6月19日星期一10:19:10 +0000资源(55)类型(流)int(0)string(0)“”

On the live server I receive this; 在实时服务器上,我收到了这个;

Message: fsockopen(): unable to connect to tcp://smtp.office365.com:587 (Connection timed out) 消息:fsockopen():无法连接到tcp://smtp.office365.com:587(连接超时)

I have tried Gmail smtp, again this works locally but not on the remote web host. 我已经尝试过Gmail smtp,这也适用于本地但不适用于远程网络主机。

Is there anything else I should try, or ask my web host to check? 还有什么我应该尝试,或让我的网站主机检查? Currently I'm out of ideas. 目前我没有想法。

Any help is appreciated. 任何帮助表示赞赏。

i dont know if this would work in your case, but i have the same issue. 我不知道这是否适用于你的情况,但我有同样的问题。 it work on my local development using homestead but in hostgator its error. 它使用宅基地在我的本地开发工作,但在hostgator中它的错误。 what i did to fix it, is i change the value of protocol to mail. 我做了什么来修复它,是我将协议的值更改为邮件。

try to change your code: 尝试更改您的代码:

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

to this: 对此:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM