【发布时间】:2012-01-11 16:01:12
【问题描述】:
我正在使用 phpmailer 发送电子邮件,当我需要连接到远程邮件服务器时,在我的主机上发送时遇到了一些问题。 我从技术支持那里得到信息,我需要将我的服务器 ip 与远程服务器绑定。 这是我第一次搞乱套接字。
不幸的是 phpmailer 使用 fsocketopen,所以我是这样更改的:
//my replacement code
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$conn = socket_connect($socket, $host, $port);
if($conn) {
$this->smtp_conn = $socket;
} else {
throw new Exception("Failed to connect to server: ".socket_last_error($socket));
}
//original phpmailer code
/**
$this->smtp_conn = @fsockopen($host, // the host of the server
$port, // the port to use
$errno, // error number if any
$errstr, // error message if any
$tval); // give up after ? secs
*/
但在更改之后我收到警告:
警告:fputs():提供的资源不是有效的流资源
警告:socket_get_status():提供的资源不是有效的流 资源
如何创建与从 fsockopen 返回的资源兼容的资源? 使用 var_dump 它说这两个变量都是套接字。但我仍然收到有关使用 socket_create 创建的资源的警告。
【问题讨论】:
标签: php email sockets phpmailer