最近博客搬家到万网的免费虚拟主机上,发现了一个bug,邮件一直无法发送。WordPress程序(3.8版本以后)默认使用的是stream_socket_client函数发信,而万网的免费虚拟主机使用的是fsockopen函数发信,因此,我们需做以下修改:
第一步、在万网的免费虚拟主机后台启用fsockopen函数(PHP.in设置 → PHP函数设置)。如下图所示:
第二步、修改WordPress程序中wp-includes/class-smtp.php文件,找到以下内容部分(202行左右):
$this->smtp_conn = @stream_socket_client( $host . ":" . $port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context );
修改为:
$this->smtp_conn = fsockopen($host, $port, $errno, $errstr);
第三步、安装WP SMTP插件(国人开发的一款插件)https://wordpress.org/plugins/wp-smtp/ ,提供一个免插件实现SMTP邮件服务的方法,将以下代码添加到主题functions.php文件中:
//使用smtp发送邮件,以163邮箱为例 add_action('phpmailer_init', 'mail_smtp'); function mail_smtp( $phpmailer ) { $phpmailer->FromName = '氪星人'; //发件人的名称 $phpmailer->Host = 'smtp.163.com'; //修改为你使用的SMTP服务器 $phpmailer->Port = 25; //SMTP端口 $phpmailer->Username = 'lyc@163.com'; //你的邮箱账号 $phpmailer->Password = '******'; //邮箱密码 $phpmailer->From = 'admin@163.com'; //你的邮箱账号 $phpmailer->SMTPAuth = true; $phpmailer->SMTPSecure = ''; //ssl对应的端口465 $phpmailer->IsSMTP(); }
本文暂时没有评论,来添加一个吧(●'◡'●)