Codeigniter SMTP无法连接 [英] Codeigniter SMTP Unable to Connect

查看:185
本文介绍了Codeigniter SMTP无法连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Codeigniter 3,并在我的网站上有一个简单的联系表。这个联系表单完全符合我的本地主机XAMPP环境,但不在我的共享网络托管(BT)上。



我不能说出问题是什么,已经与他们的支持联系,显然如果电子邮件帐户能够通过电子邮件客户端(可以)发送和接收电子邮件,他们不提供任何其他支持:/



我可以使用此帐户登录Office365发送和接收电子邮件。 Office365中的smpt设置为:

 服务器名称:smtp.office365.com 
端口:587
加密方法:STARTTLS

我目前的代码如下:

  $ config ['protocol'] ='smtp'; 
$ config ['smtp_host'] ='smtp.office365.com'; //也试过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\\\
;

在本地主机中,电子邮件发送,没有问题。在现场Web主机上,我收到以下错误;


消息:fsockopen():无法连接到smtp.office365.com:587
(连接超时)


我已经看到问题可能与OpenSSL无法启用,网络主机已确认已启用。我还使用以下代码检查了加载的扩展;

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

返回;

  Array 

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

我检查过我可以使用以下代码连接到smtp服务器:

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

在我的本地主机上,我收到以下消息:


220 VI1PR0602CA0001.outlook.office365.com Microsoft ESMTP邮件服务
准备在星期一,19六月2017 10:19:10 +0000资源(55)类型(流)
int(0)string(0)


在实时服务器上,我收到这个;


消息:fsockopen():无法连接到
tcp://smtp.office365.com:587(连接超时)


我已经尝试过Gmail smtp,这样做本身就不在远程Web主机上。



还有什么我应该尝试,还是请我的网站主机检查?目前我没有想法。



任何帮助都不胜感激。

解决方案

我不知道这是否适用于你的情况,但是我也有同样的问题。它工作在我的本地开发使用homestead,但在hostgator它的错误。我做了什么来解决它,是我将协议的价值改为邮件。



尝试更改代码:



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

到:

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


I'm using Codeigniter 3 and have a simple contact form on my website. This contact form works perfectly on my localhost XAMPP environment, but not on my shared web hosting (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. The smpt settings in Office365 are;

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. On the live web host I receive the following error;

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

I've read that the issue could be related to OpenSSL not being enabled, however the web host has confirmed it is enabled. 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;

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

On the live server I receive this;

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

I have tried Gmail smtp, again this works locally but not on the remote web host.

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. 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';

这篇关于Codeigniter SMTP无法连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆