厘米天空
当前位置:厘米天空 > 建站笔记 > 万网免费主机smtp邮件回复失效的解决办法

万网免费主机smtp邮件回复失效的解决办法

更新时间:2023-04-11 17:46:54浏览次数:556+次

  网站搬家到万网也遇到了一些小问题,搬家的过程还算顺利,但是也遇到了一点小问题,邮件回复功能又失效了。上网查询了一下,需要使用fsockopen函数。但是WordPress的SMTP默认发送方式为steam_connect_client而非fsockopen,所以需要打开/wp-include/class-smtpp.php 200-209行左右,将
  
  $socket_context = stream_context_create($options);
  
  $this->smtp_conn = @stream_socket_client(
  
  $host . ":" . $port,
  
  $errno,
  
  $errstr,
  
  $timeout,
  
  STREAM_CLIENT_CONNECT,
  
  $socket_context
  
  );
  
  这段改为
  
  $this->smtp_conn = @fsockopen($host,$port,$errno,$errstr,$timeout);
  
  就行了,当然前提是万网虚拟主机PHP.ini设置那里要保证fsockopen函数是打开的。
 
万网免费主机smtp邮件回复失效的解决办法
  
  ?
  
  wordpress4.3已变成273-297行
  
  if ($streamok) {
  
  $socket_context = stream_context_create($options);
  
  //Suppress errors; connection failures are handled at a higher level
  
  $this->smtp_conn = @stream_socket_client(
  
  $host . ":" . $port,
  
  $errno,
  
  $errstr,
  
  $timeout,
  
  STREAM_CLIENT_CONNECT,
  
  $socket_context
  
  );
  
  } else {
  
  //Fall back to fsockopen which should work in more places, but is missing some features
  
  $this->edebug(
  
  "Connection: stream_socket_client not available, falling back to fsockopen",
  
  self::DEBUG_CONNECTION
  
  );
  
  $this->smtp_conn = fsockopen(
  
  $host,
  
  $port,
  
  $errno,
  
  $errstr,
  
  $timeout
  
  );
  
  }