TaterLi 个人博客

WordPress 邮件代理

开发了一个小小的插件,只有几行代码.

这个解决一个问题是,使用国内邮箱发国外到达率低,使用国外邮箱国内很难访问,使用邮件代发服务嘛又很多有低消或者各种认证,因此,用虚拟主机解决问题看看.

另外它始终只是玩具一般的东西,所以文档也不会写,就当个记录,分为一端在虚拟主机部署,一端在本机部署.

客户端:

<?php

/**
 * @package Mail_Proxy
 * @version 1.0.0
 */

/*
Plugin Name: 邮件代理
Plugin URI: https://www.taterli.com/
Description: 把发送邮件的需求代理到远程虚拟主机去,使用远程的虚拟主机发邮件,这样就可以使用墙外的邮件服务了.
Author: TaterLi
Version: 1.0.0
Author URI: https://www.taterli.com/
*/

function remote_mail($args)
{
	$ret = wp_remote_post(
		'http://send.example.org/send.php',
		array(
			'blocking'    => true,
			'headers'     => array('Content-Type' => 'application/x-www-form-urlencoded'),
			'body'        => array('to' => base64_encode($args['to']), 'subject' => base64_encode($args['subject']), 'message' => base64_encode($args['message']), 'headers' => base64_encode($args['headers'])),
		)
	);
}

add_filter('wp_mail', 'remote_mail');

服务器端:

<?php
$to = base64_decode($_POST['to']);
$subject = base64_decode($_POST['subject']);
$message = base64_decode($_POST['message']);
$headers = base64_decode($_POST['headers']);

mail($to,$subject,$message,$headers);

毕竟虚拟主机每天配额不用白不用.

退出移动版