Codeigniter SMTP 无法连接
我正在使用 Codeigniter 3,并在我的网站上有一个简单的联系表.此联系表单在我的本地 XAMPP 环境中完美运行,但不适用于我的共享虚拟主机 (BT).
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 :/
我可以使用此帐户登录 Office365 以发送和接收电子邮件.Office365 中的 smpt 设置是;
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
我目前的代码如下;
$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'] = "
";
在本地主机中发送电子邮件并且没有问题.在实时网络主机上,我收到以下错误;
In localhost the email sends and there are no issues. On the live web host I receive the following error;
消息:fsockopen():无法连接到 smtp.office365.com:587(连接超时)
Message: fsockopen(): unable to connect to smtp.office365.com:587 (Connection timed out)
我了解到该问题可能与未启用 OpenSSL 有关,但是 Web 主机已确认已启用它.我还使用以下代码检查了加载的扩展;
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>";
返回;
Array
(
[0] => Core
[1] => date
[2] => ereg
[3] => libxml
[4] => openssl
[5] => pcre
etc
etc
)
我已检查我是否能够使用以下代码连接到 smtp 服务器;
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 邮件服务准备在 2017 年 6 月 19 日星期一 10:19:10 +0000 类型(流)的资源(55)int(0) 字符串(0) ""
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;
消息:fsockopen():无法连接到tcp://smtp.office365.com:587(连接超时)
Message: fsockopen(): unable to connect to tcp://smtp.office365.com:587 (Connection timed out)
我已经尝试过 Gmail smtp,这同样适用于本地,但不适用于远程 Web 主机.
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.
感谢任何帮助.
推荐答案
我不知道这是否适用于你的情况,但我有同样的问题.它使用宅基地在我的本地开发中工作,但在 hostgator 中它的错误.我做了什么来解决它,是我将协议的值更改为邮件.
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.
尝试更改您的代码:
$config['protocol'] = 'smtp';
到这里:
$config['protocol'] = 'mail';
相关文章